ESPHome binding for the Native API [4.0.0.0;6.0.0.0)

After some more investigation, I think the binding doesn’t play nice with:

esphome:
  name: haard-eetkamer
[...]
switch:
  - platform: template
    name: winter_OFF
    id: winter_OFF
    turn_on_action:
      - then:
        - switch.turn_on: IN3
        - delay: 8s
        - switch.turn_off: IN3
        - switch.template.publish:
            id: winter_OFF
            state: OFF

Apparently, the status of item haard_eetkamer_winter_OFF never changes to ON (unless “auto-update” is enabled), and later doesn’t get an update to OFF (which I would expect from switch.template.publish).

I can’t assist much without complete DEBUG logs :winking_face_with_tongue:

These are relevant entries in the event log:

2024-11-04 23:32:02.808 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'haard_salon_winter_OFF' received command ON
2024-11-04 23:32:02.917 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'haard_salon_IN3' changed from OFF to ON
2024-11-04 23:32:10.924 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'haard_salon_IN3' changed from ON to OFF

These are the DEBUG logs:

2024-11-04 23:32:02.834 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Sending message type SwitchCommandRequest with content 'key: 2499407148
state: true'
2024-11-04 23:32:02.834 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-salon] Writing data 30 bytes
2024-11-04 23:32:02.915 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:02.915 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:02.915 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:02.915 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Received packet of type 26 with data [13, -9, 110, -120, 31, 16, 1]
2024-11-04 23:32:02.916 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received message type SwitchStateResponse with content 'key: 529034999
state: true'
2024-11-04 23:32:03.299 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Sending ping
2024-11-04 23:32:03.300 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Sending message type PingRequest with content ''
2024-11-04 23:32:03.300 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-salon] Writing data 23 bytes
2024-11-04 23:32:03.325 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Sending ping
2024-11-04 23:32:03.326 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Sending message type PingRequest with content ''
2024-11-04 23:32:03.326 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-eetkamer] Writing data 23 bytes
2024-11-04 23:32:03.435 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:03.435 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:03.435 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:03.436 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Received packet of type 8 with data []
2024-11-04 23:32:03.436 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received message type PingResponse with content ''
2024-11-04 23:32:03.436 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received ping response
2024-11-04 23:32:03.436 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:03.436 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:03.436 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:03.437 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Received packet of type 8 with data []
2024-11-04 23:32:03.437 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received message type PingResponse with content ''
2024-11-04 23:32:03.437 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received ping response
2024-11-04 23:32:10.921 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:10.921 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:10.921 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:10.922 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Received packet of type 26 with data [13, -9, 110, -120, 31]
2024-11-04 23:32:10.922 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received message type SwitchStateResponse with content 'key: 529034999'
2024-11-04 23:32:13.299 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Sending ping
2024-11-04 23:32:13.300 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Sending message type PingRequest with content ''
2024-11-04 23:32:13.300 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-salon] Writing data 23 bytes
2024-11-04 23:32:13.325 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Sending ping
2024-11-04 23:32:13.325 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Sending message type PingRequest with content ''
2024-11-04 23:32:13.326 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-eetkamer] Writing data 23 bytes
2024-11-04 23:32:13.359 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:13.359 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:13.359 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:13.359 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Received packet of type 8 with data []
2024-11-04 23:32:13.359 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received message type PingResponse with content ''
2024-11-04 23:32:13.360 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received ping response
2024-11-04 23:32:13.363 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:13.363 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:13.363 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:13.363 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Received packet of type 8 with data []
2024-11-04 23:32:13.364 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received message type PingResponse with content ''
2024-11-04 23:32:13.364 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received ping response
2024-11-04 23:32:23.299 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Sending ping
2024-11-04 23:32:23.300 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Sending message type PingRequest with content ''
2024-11-04 23:32:23.300 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-salon] Writing data 23 bytes
2024-11-04 23:32:23.325 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Sending ping
2024-11-04 23:32:23.326 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Sending message type PingRequest with content ''
2024-11-04 23:32:23.326 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-eetkamer] Writing data 23 bytes
2024-11-04 23:32:23.374 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 0
2024-11-04 23:32:23.389 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:23.389 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:23.389 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:23.389 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Received packet of type 8 with data []
2024-11-04 23:32:23.390 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received message type PingResponse with content ''
2024-11-04 23:32:23.390 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received ping response
2024-11-04 23:32:23.394 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:23.394 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:23.394 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:23.395 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Received packet of type 8 with data []
2024-11-04 23:32:23.395 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received message type PingResponse with content ''
2024-11-04 23:32:23.395 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received ping response
2024-11-04 23:32:33.299 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Sending ping
2024-11-04 23:32:33.300 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Sending message type PingRequest with content ''
2024-11-04 23:32:33.300 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-salon] Writing data 23 bytes
2024-11-04 23:32:33.325 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Sending ping
2024-11-04 23:32:33.326 [DEBUG] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Sending message type PingRequest with content ''
2024-11-04 23:32:33.326 [TRACE] [home.internal.comm.ESPHomeConnection] - [haard-eetkamer] Writing data 23 bytes
2024-11-04 23:32:33.405 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 0
2024-11-04 23:32:33.418 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:33.418 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:33.418 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:33.418 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-eetkamer] Received packet of type 8 with data []
2024-11-04 23:32:33.419 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received message type PingResponse with content ''
2024-11-04 23:32:33.419 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-eetkamer] Received ping response
2024-11-04 23:32:33.427 [TRACE] [ome.internal.comm.ConnectionSelector] - Num selected keys: 1
2024-11-04 23:32:33.428 [TRACE] [ome.internal.comm.ConnectionSelector] - Processing key readable=true
2024-11-04 23:32:33.428 [TRACE] [ome.internal.comm.ConnectionSelector] - Received data
2024-11-04 23:32:33.428 [TRACE] [me.internal.comm.AbstractFrameHelper] - [haard-salon] Received packet of type 8 with data []
2024-11-04 23:32:33.428 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received message type PingResponse with content ''
2024-11-04 23:32:33.428 [DEBUG] [home.internal.handler.ESPHomeHandler] - [haard-salon] Received ping response

This are relevant parts of the ESP yaml:

esphome:
  name: haard-salon
[...]
switch:
  - platform: gpio 
    pin: GPIO33  #D5 ## The initial instructions were GPIO14, but according to the manual, that is "HIGH" on boot, so I chose another pin.
    name: "IN3" 
    id: IN3
    inverted: true
  - platform: template
    name: winter_OFF
    id: winter_OFF
    turn_on_action:
      - then:
        - switch.turn_on: IN3
        - delay: 8s
        - switch.turn_off: IN3
        - switch.template.publish:
            id: winter_OFF
            state: OFF

OK, in your original post ESPHome binding for the Native API [4.0.0;6.0.0) - #300 by ErikDB you refer to an ESP device called haard-eetkamer, while in the latest you refer to haard-salon. Confusing since your logs contains statements from both devices.

It is clear from the log that haard-salon switch winter_OFF receives the command and sends state responses for IN3, but not for winter_OFF.

Guessing section:
I see that you use turn_on_action, but you don’t publish an ON state when the command is received, hence when you in the last line requests the state to change to OFF, no update is sent from the device as winter_OFF already (and probably always is) in state OFF.
CleanShot 2024-11-05 at 08.56.50

Maybe what you were actually looking for is

beer_me

Happy hacking!

1 Like

Apologies. They’re identical twins. :slight_smile:

The rest of your help did the trick! Hooray!

  - platform: template
    name: winter_OFF
    id: winter_OFF
    turn_on_action:
      - then:
        - switch.template.publish:
            id: winter_OFF
            state: ON
        - switch.turn_on: IN3
        - delay: 8s
        - switch.turn_off: IN3
        - switch.template.publish:
            id: winter_OFF
            state: OFF
1 Like

Sometimes my fireplace (‘governed’ by an output relay run by ESP32) goes out without my command, and without the relevant switche in openHAB being turned OFF. I need to do some digging in the logs, obviously, but I wonder whether the ESPHome binding supports the Logger component?

And if so, how it would work :sweat_smile:

Check this out GitHub - seime/openhab-esphome: ESPHome native API implementation for openHAB binding

Apologies. I should’ve checked the docs first, obviously :grimacing:

In step 3, is ESPHOMEDEVICE a placeholder, and should I write the actual device name? Or is it really ESPHOMEDEVICE, and does that catch all logs from all devices?

In the example below, the logs read varmtvann

Use ESPHOMEDEVICE, it is not a placeholder. It is the name of the logger that will receive the log statements from the device, and is referred to inside the binding. This is to avoid mixing binding log statements (OH) and device log statements (ESPHOME).

varmtvann in the log messages is just the name of the (my) esphome device, which in your case would be haard-salon, haard-eetkamer and others depending on whether you enable logging in each thing configuration.

2 Likes

Little bit off topic to this binding, but does someone know an easy way how to compile a firmware for esphome without home assistant? 95% of the available tutorials are for home assistant. I tried the “command line” approch on their wiki but failed because my windows 10 pc was missing an c++ addon. Tried to install it with Microsoft visual studio (?) But didnt help.

I use PowerShell on my Windows 11. Don’t you get an error or something with guidelines on what to do, or where you can install that C++ addon?

I just installed the brew package on my Mac, I assume a similar package is available on windows.
Comes with a nice web ui.
Also https://web.esphome.io/ exists which is supposed to be a light version of the full esphome setup. Have not tried though.

Unless I’m missing something, the easiest way I found was to set up ESPHome in a docker like described in the

described here

1 Like

This requires Docker… I would think this is the easiest way: Installing ESPHome Manually - ESPHome - Smart Home Made Simple

1 Like

I installed ESPHome manually on a raspberry pi. I tried it on a pi 4 and a pi 5. The pi 5 is faster, but the pi 4 worked just fine. Once installed, you start the ESPHome console on the Pi, and access it with a browser. The console looks like what you see in the HA docs. You can then access the console from a windows or mac computer from a browser, using the IP address of the Pi.
The advantage of using the pi is that if you can reflash the3 OS and start over if you goof it up. For me, it was easier than trying to get up to speed with docker, and I didn’t get things installed on my windows computer that I may not want permanently.

FYI:
It looks like ESPHome Binding is currently not compatible with OH 4.3.0!

I created an issue for this:
Not Compatible with OH 4.3.0 · Issue #34 · seime/openhab-esphome

What I want from the ESPHome binding, works…

Actually, if you install the Bluetooth binding it all works again.

I’ve recently merged a preliminary Bluetooth proxy that allows your ESPHome device to also work as a proxy to other Bluetooth devices. For now only one way support works meaning devices that broadcast data can be picked up. I’ve tested this with GitHub - rbaron/b-parasite: 🌱💧 An open source DIY soil moisture sensor devices and a Shelly BLU button - they all send BTHome protocol data. BTHome data is supported by the openHAB BTHome binding.

I simply forgot at about this dependency when I merged this 6 month old PR, but I’ll try to find a way to mark the Bluetooth binding as an optional bundle/feature dependency. If any of you knows how to do this I’m happy for any hints :slight_smile:

1 Like

@seime, is CoAp necessary? Maybe that’s the culprit?