OK, I found out that I must enable “Retain Msg” in ESPEasy:
I also successfully created switch, which turn ON the relay 1 or 2.
Code:
#KONTROLA: http://192.168.3.99/
# HA - 192.168.3.99 - ESPEasy Klop - LED
# https://community.home-assistant.io/t/espeasy-mqtt-configuration-ha/157415
# RELAY 1
- platform: template
switches:
espeasy_klop_led_stalna:
friendly_name: "Klop - LED osvetlitev (stalna)"
value_template: "{{ is_state('binary_sensor.espeasy_klop_led_stalno_stanje', 'on') }}"
turn_on:
- service: mqtt.publish
data:
payload: 'relay,1,1'
topic: '/ESPEasy-Klop-LED/gpio/cmd'
turn_off:
- service: mqtt.publish
data:
payload: 'relay,1,0'
topic: '/ESPEasy-Klop-LED/gpio/cmd'
#KONTROLA: http://192.168.3.99/
# HA - 192.168.3.99 - ESPEasy Klop - LED
# https://community.home-assistant.io/t/espeasy-mqtt-configuration-ha/157415
# RELAY 2
- platform: template
switches:
espeasy_klop_led_senzor:
friendly_name: "Klop - LED osvetlitev (senzor)"
value_template: "{{ is_state('binary_sensor.espeasy_klop_led_senzor_stanje', 'on') }}"
turn_on:
- service: mqtt.publish
data:
payload: 'relay,0,1'
topic: '/ESPEasy-Klop-LED/gpio/cmd'
turn_off:
- service: mqtt.publish
data:
payload: 'relay,0,0'
topic: '/ESPEasy-Klop-LED/gpio/cmd'
But I have problem with status… it simply do not working… I do not get any status off MQTT switch (relay) and because of that switch turn OFF (in lovelace) just after I click on it… Relay 1 or 2 turn ON successfully… Off course, then I can not turn OFF because the HA has no status from MQTT and it’s still showing that it’s OFF…
binary_sensor which is not working… Do I need to do something in ESPEasy or this code is not correct? I also tried with state_topic: ‘/ESPEasy-Klop-LED/status/LWT’ but it was the same…
# HA - 192.168.3.99 - ESPEasy Klop - LED
# https://community.home-assistant.io/t/espeasy-mqtt-configuration-ha/157415
# RELAY 1
- platform: mqtt
name: ESPEasy Klop - LED stalno (stanje)
state_topic: '/ESPEasy-Klop-LED/status'
value_template: >-
{% if 'relay,1,0' in value %}
{{'OFF'}}
{% elif 'relay,1,1' in value %}
{{'ON'}}
{% endif %}
# HA - 192.168.3.99 - ESPEasy Klop - LED
# https://community.home-assistant.io/t/espeasy-mqtt-configuration-ha/157415
# RELAY 2
- platform: mqtt
name: ESPEasy Klop - LED senzor (stanje)
state_topic: '/ESPEasy-Klop-LED/status'
value_template: >-
{% if 'relay,0,0' in value %}
{{'OFF'}}
{% elif 'relay,0,1' in value %}
{{'ON'}}
{% endif %}
Do anybody have some experience with that?
I found some topics on forums:
https://www.letscontrolit.com/forum/viewtopic.php?f=6&t=1822&p=8545#p8545
https://www.letscontrolit.com/forum/viewtopic.php?t=320
But I didn’t figure it out what the correct solution is…
From developer tools it looks like this: