How to connect with ESP Easy

Hi
I have a problem how to properly import data from Esp Easy.
Ie I have connect ESP’s GPIO with on/off contact. I want to read 0/1 and change it to on/off.
I tried with MQTT but gave up. Simpler is to use http binding.
I can config it and connect, problem is with proper channel configuration and site transformation.
Could somebody help me and suggest proper site transform for
“kominek2” ?
I can output data via json or measurements files:
json:

{
  "System": {
    "Load": 8.99,
    "Load LC": 15309,
    "Build": 20241222,
    "Git Build": "mega-20241222",
    "System Libraries": "ESP82xx Core 2843a5ac, NONOS SDK 2.2.2-dev(38a443e), LWIP: 2.1.2 PUYA support",
    "Plugin Count": 75,
    "Plugin Description": [
      "Normal",
      "Collection",
      "Collection_B",
      "No Debug Log"
    ],
    "Build Time": "Dec 22 2024 23:37:47",
    "Binary Filename": "ESP_Easy_mega_20241222_collection_B_ESP8266_4M1M",
    "Local Time": "1970-01-01 00:59:42",
    "Time Source": "No time set",
    "Time Wander": 0,
    "Use NTP": "false",
    "Unit Number": 0,
    "Unit Name": "ESP_Easy",
    "Uptime": 60,
    "Uptime (ms)": 3583396,
    "Last Boot Cause": "Soft Reboot",
    "Reset Reason": "Software/System restart",
    "CPU Eco Mode": "false",
    "Free RAM": 14216,
    "Free Stack": 3376,
    "ESP Chip Model": "ESP8266EX",
    "Flash Chip ID": "0x1640C8",
    "Flash Chip Vendor": "0xC8",
    "Flash Chip Model": "0x4016",
    "Flash Chip Real Size": 4194304,
    "Flash Chip Speed": 40,
    "Flash IDE Mode": "DOUT",
    "SPIFFS Size": 957314,
    "Sunrise": "6:00",
    "Sunset": "18:07",
    "Timezone Offset": 0,
    "Latitude": 0,
    "Longitude": 0,
    "Syslog Log Level": "Info",
    "Serial Log Level": "Info",
    "Web Log Level": "None"
  },

  "nodes": [
    {
      "nr": 0,
      "name": "ESP_Easy",
      "build": 20241222,
      "platform": "ESP Easy Mega",
      "load": 8.63,
      "ip": "192.168.1.31",
      "age": 4889
    }
  ],
  "Sensors": [
    {
      "TaskValues": [
        {
          "ValueNumber": 1,
          "Name": "CountDelta",
          "NrDecimals": 1,
          "Value": 0
        }
      ],
      "DataAcquisition": [
        {
          "Controller": 1,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 2,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 3,
          "IDX": 0,
          "Enabled": "false"
        }
      ],
      "TaskInterval": 10,
      "Type": "Pulse Counter - DS2423",
      "TaskName": "Licznik_10s",
      "TaskDeviceNumber": 100,
      "TaskDeviceGPIO1": 2,
      "TaskEnabled": "true",
      "TaskNumber": 1
    },
    {
      "TaskValues": [
        {
          "ValueNumber": 1,
          "Name": "CountDelta",
          "NrDecimals": 3,
          "Value": 1.6
        }
      ],
      "DataAcquisition": [
        {
          "Controller": 1,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 2,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 3,
          "IDX": 0,
          "Enabled": "false"
        }
      ],
      "TaskInterval": 60,
      "Type": "Pulse Counter - DS2423",
      "TaskName": "Licznik_min",
      "TaskDeviceNumber": 100,
      "TaskDeviceGPIO1": 2,
      "TaskEnabled": "true",
      "TaskNumber": 2
    },
    {
      "TaskValues": [
        {
          "ValueNumber": 1,
          "Name": "Gaz",
          "NrDecimals": 3,
          "Value": 17.6
        }
      ],
      "DataAcquisition": [
        {
          "Controller": 1,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 2,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 3,
          "IDX": 0,
          "Enabled": "false"
        }
      ],
      "TaskInterval": 600,
      "Type": "Pulse Counter - DS2423",
      "TaskName": "Licznik_10min",
      "TaskDeviceNumber": 100,
      "TaskDeviceGPIO1": 2,
      "TaskEnabled": "true",
      "TaskNumber": 3
    },
    {
      "TaskValues": [
        {
          "ValueNumber": 1,
          "Name": "CountDelta",
          "NrDecimals": 3,
          "Value": 0
        }
      ],
      "DataAcquisition": [
        {
          "Controller": 1,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 2,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 3,
          "IDX": 0,
          "Enabled": "false"
        }
      ],
      "TaskInterval": 3600,
      "Type": "Pulse Counter - DS2423",
      "TaskName": "Licznik_1h",
      "TaskDeviceNumber": 100,
      "TaskDeviceGPIO1": 2,
      "TaskEnabled": "true",
      "TaskNumber": 4
    },
    {
      "TaskValues": [
        {
          "ValueNumber": 1,
          "Name": "CountDelta",
          "NrDecimals": 3,
          "Value": 0
        }
      ],
      "DataAcquisition": [
        {
          "Controller": 1,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 2,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 3,
          "IDX": 0,
          "Enabled": "false"
        }
      ],
      "TaskInterval": 43200,
      "Type": "Pulse Counter - DS2423",
      "TaskName": "Licznik_12h",
      "TaskDeviceNumber": 100,
      "TaskDeviceGPIO1": 2,
      "TaskEnabled": "true",
      "TaskNumber": 5
    },
    {
      "TaskValues": [
        {
          "ValueNumber": 1,
          "Name": "State",
          "NrDecimals": 0,
          "Value": 1
        }
      ],
      "DataAcquisition": [
        {
          "Controller": 1,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 2,
          "IDX": 0,
          "Enabled": "false"
        },
        {
          "Controller": 3,
          "IDX": 0,
          "Enabled": "false"
        }
      ],
      "TaskInterval": 50,
      "Type": "Switch input - Switch",
      "TaskName": "kominek2",
      "TaskDeviceNumber": 1,
      "TaskDeviceGPIO1": 13,
      "TaskEnabled": "true",
      "TaskNumber": 7
    }
  ],
  "TTL": 10000
}

and (easier) metric file:

# HELP espeasy_uptime current device uptime in minutes
# TYPE espeasy_uptime counter
espeasy_uptime 38
# HELP espeasy_load device percentage load
# TYPE espeasy_load gauge
espeasy_load 11.31
# HELP espeasy_free_ram device amount of RAM free in Bytes
# TYPE espeasy_free_ram gauge
espeasy_free_ram 18680
# HELP espeasy_free_stack device amount of Stack free in Bytes
# TYPE espeasy_free_stack gauge
espeasy_free_stack 3616
# HELP espeasy_wifi_rssi Wifi connection Strength
# TYPE espeasy_wifi_rssi gauge
espeasy_wifi_rssi -46
# HELP espeasy_wifi_connected Time wifi has been connected in milliseconds
# TYPE espeasy_wifi_connected counter
espeasy_wifi_connected 1961000
# HELP espeasy_wifi_reconnects Number of times Wifi has reconnected since boot
# TYPE espeasy_wifi_reconnects counter
espeasy_wifi_reconnects 1
# HELP espeasy_device_Licznik_10s Values from connected device
# TYPE espeasy_device_Licznik_10s gauge
espeasy_device_Licznik_10s{valueName="CountDelta"} 0.0
# HELP espeasy_device_Licznik_min Values from connected device
# TYPE espeasy_device_Licznik_min gauge
espeasy_device_Licznik_min{valueName="CountDelta"} 2.400
# HELP espeasy_device_Licznik_10min Values from connected device
# TYPE espeasy_device_Licznik_10min gauge
espeasy_device_Licznik_10min{valueName="Gaz"} 12.000
# HELP espeasy_device_Licznik_1h Values from connected device
# TYPE espeasy_device_Licznik_1h gauge
espeasy_device_Licznik_1h{valueName="CountDelta"} 0.000
# HELP espeasy_device_Licznik_12h Values from connected device
# TYPE espeasy_device_Licznik_12h gauge
espeasy_device_Licznik_12h{valueName="CountDelta"} 0.000
# HELP espeasy_device_kominek2 Values from connected device
# TYPE espeasy_device_kominek2 gauge
espeasy_device_kominek2{valueName="State"} 1

In my experience HTTP is as if not more complicated than using MQTT. It’s less flexible too because it has to poll instead of having the new data published directly. It can work with HTTP for sure, but MQTT would in fact be the simpler solution, expecially given the JSON that you get from the HTTP polling request.

ESP Home even supports the Home Assistant MQTT standard so OH could just discover the devices and create the Things automatically meaning you don’t have to configure anything at all on the OH Things side.

There is also an ESP Home binding on the marketplace you could use: ESPHome binding for the Native API [4.0.0;5.0.0)

A JSONPATH transform won’t work here I think becuase the JSON uses a lot of arrays. So you might need to use a JS transform script to parse the raw JSON into a JS Object. Then you should be able to navigate and filter down to the record for “kominek2”. It’s a complicated JSON so I can’t say for sure if this is correct but it illistrates the approach:

JSON.parse(input).sensors.find(s => s.TaskName == "kominek2").TaskValues[0].Value

But you’ll be much better off using the add-on or MQTT in the long run.

I think he is talking about ESP Easy.

I don’t know how to do this through HTTP binding, but here is an example through MQTT:

This is a magnetic contact, connected to a gpio and ground, linked to a Channel which reads 0 and 1.

The mqtt topic, configured through ESP Easy, sends 0 and 1 to the broker on esp8266five/doorcontact
Create a Contact ItemType and link that channel to it.

You should now receive OPEN and CLOSED to that item. If you need ON and OFF, that is a different story, but first things first.

I guess this works exactly the same with a Switch Itemtype to get ON and OFF, but I haven’t tried yet.

The “secret” is to fill the Custom On/Open Value and Custom Off/Closed Value with 0 and 1.

Yes, I somehow got to the wrong one. I’m not sure how.

To show the full example, click on the code tab and paste the full Thing YAML using code fences.

I use ESP Easy too. I don’t have any contacts but I do get sensor readings from them.

Here’s one of my Things.

UID: mqtt:topic:mosquitto:basement_sensors
label: Rich's Office Sensors
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: Connection Lost
  availabilityTopic: basement-sensors/status/LWT
  payloadAvailable: Connected
bridgeUID: mqtt:broker:broker
location: Rich's Office
channels:
  - id: light
    channelTypeUID: mqtt:number
    label: Light Level
    configuration:
      stateTopic: basement-sensors/light/light
  - id: online
    channelTypeUID: mqtt:switch
    label: Online Status
    configuration:
      stateTopic: basement-sensors/status/LWT
      off: Connection Lost
      on: Connected
  - id: temp
    channelTypeUID: mqtt:number
    label: Temperature
    configuration:
      stateTopic: basement-sensors/climate/temperature
      unit: °F
  - id: humi
    channelTypeUID: mqtt:number
    label: Humidity
    configuration:
      stateTopic: basement-sensors/climate/humidity
      unit: "%"

The ESP Easy MQTT Controller config is

I haven’t upgraded these in a very long time though so the new ESP Easy may look and be configured differently. The full “Controller Publish” fleld is %sysname%/%tskname%/%valname%. The topic struture ends up looking like:

There is nothing to parse because each sensor and piece of information gets published to it’s own topic.

Thank you, guys !
Based on your suggestion I gave up with http. I have installed Mosquito and MQTT binding.
All is connected, including EspEasy.
Now, how to config it on OH in order to get values ?
From Things I have MQTT Broker and Generic MQTT Thing. Do I need something else ?

How to configure channels ?
Auto discovery do not find MQTT.
My Esp Config:

and devices:

In OH in Generic MQTT Thing in channel I added:


but it gave me no result …

EDIT
ok, I mixed it up client it and sysname.
When input: ESP_Easy/kominek/State then it read the value, but it is not stable. It set it open and then after few seconds to UNDEF then again to open …

EDIT2
I still kept http binding linked with same item, thats why it changed to UNDEF. I removed it and not it looks ok.
Only one quest left - how to automaticaly find all MQTT devices/sensors ?

ESP Easy does not provide the necessary data to have openHAB autodiscover Things and Channels.

ESPHome does, but you need to reflash and reconfigure all of your devices.

But it is not that hard to create a MQTT Generic Thing and add Channels to it.

One easy way to find the state topics is with the help of a MQTT sniffer, for example MQTT Explorer:

Connect the sniffer to your broker and wait for your devices to send data. On the right hand side you can easy read the state topics for your Channels.

1 Like