sairon / esphome-nspanel-lovelace-ui

ESPHome component for NSPanel Lovelace UI
Other
125 stars 31 forks source link

Using Home Assistant API instead of MQTT #34

Open afarago opened 7 months ago

afarago commented 7 months ago

Based on the already merged PR to joBr99/nspanel-lovelace-ui#1007 I would love to see the use of HA API. It results in smoother and faster communication through HA events and HA services.

esphome needs small config change, optional new/renamed triggers

nspanel_lovelace:
  use_api: True
  on_message_from_nextion:
    - lambda: |-
        ESP_LOGD("main", "message from nextion: %s", x.c_str());
  on_message_to_nextion:
    - lambda: |-
        ESP_LOGD("main", "message to nextion: %s", x.c_str());

nspanel.cpp automatically adds necessary HA service that the appdaemon backend can call (customrecv, updatetft, gerversion)

======

Afterwards HA ESP device needs explicit permission to use service calls. image

sairon commented 7 months ago

Thanks for the PR! It will unfortunately conflict with changes from #33, so either we can hold it off until that one is merged, or you can rebase it to use that PR's branch as base, so we can move on faster once it's merged (as I'd like to merge that one first, sunce it doesn't introduce any breaking changes like this one).

Also note that the new add-on that @joBr99 is currently working on and is supposed to replace the AppDaemon backend doesn't implement the API support yet, so it's something that should be looked into as well.

joBr99 commented 7 months ago

Implemented support for the API yesterday evening :)

twasilczyk commented 5 months ago

Is this still supposed to work? I did the following:

But I'm still seeing "Waiting for content". ESPHome boots up and I see the logs (also the one about successful connection - see below). Switching use_api to False and restoring commented out mqtt lines makes it work again.

[21:39:11][D][api:102]: Accepted 192.168.1.2
[21:39:12][D][api.connection:1121]: Home Assistant 2024.1.5 (192.168.1.2): Connected successfully