ESPEasy MQTT configuration + HA

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… :frowning:
image

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:

Can you look with MQTT.FX, MQTT Explorer or MQTT lens what

'/ESPEasy-Klop-LED/status'

exactly returns ?

I tried two variants and get back this:

Cut and past the message under

'/ESPEasy-Klop-LED/status'

it is not visible in the screenshot

There is nothing?

Empty, blank msg…

This is json msg under “Show JSON” button:

{“System”:{
“Build”:20102,
“Git Build”:“xuryV0.1”,
“Local time”:“2019-12-24 14:12:42”,
“Unit”:3,
“Name”:“ESPEasy-Klop-LED”,
“Uptime”:8365,
“Load”:39,
“Load LC”:10835,
“Free RAM”:13280
},
“WiFi”:{
“Hostname”:“ESPEasy-Klop-LED-3”,
“IP config”:“Static”,
“IP”:“192.168.3.99”,
“Subnet Mask”:“255.255.255.0”,
“Gateway IP”:“192.168.3.1”,
“MAC address”:“SECURITY”,
“DNS 1”:“192.168.3.1”,
“DNS 2”:“0.0.0.0”,
“SSID”:“SECURITY”,
“BSSID”:“SECURITY”,
“Channel”:6,
“Connected msec”:501949767,
“Last Disconnect Reason”:1,
“Last Disconnect Reason str”:"(1) Unspecified",
“Number reconnects”:1,
“RSSI”:-73
},
“Sensors”:[
{
“TaskNumber”:1,
“Type”:“Serial MCU controlled switch”,
“TaskName”:“Relay”,
“TaskValues”: [
{“ValueNumber”:1,
“Name”:“Relay0”,
“Value”:1},
{“ValueNumber”:2,
“Name”:“Relay1”,
“Value”:0},
{“ValueNumber”:3,
“Name”:“Relay2”,
“Value”:0}]
}
]
}

1 Like

https://www.letscontrolit.com/forum/viewtopic.php?t=1822

Yea, I read this, and if am honest, I did not understand what would be solution in my case…

You should set the retain flag :

and watch for a message like this :

/ESPEasy-Klop-LED/relay14/state

Subscribe in your mqtt client to /ESPEasy-Klop-LED/# , switch something and look what messages pass by.

MQTT retain msg is already enabled (my second post):

And I got back this when I publish:
/ESPEasy-Klop-LED/gpio/cmd
relay,0,0 or relay,0,1

So you should use this :

# 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/gpio/cmd'
    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/gpio/cmd'
    value_template: >- 
      {% if 'relay,0,0' in value %}   
        {{'OFF'}}
      {% elif 'relay,0,1' in value %}
        {{'ON'}}
      {% endif %}

Give me 5 minutes, I will report if it’s working…

Binary sensor is now working:

But when I try to close relay0:
image

And it seems as that it works:
image

But in reality nothing happens, relay is still ON…

I will try to restart everything… maybe is something somewhere stuck… must check everything…

And how did it end? Were you able to make it work?

I’m using old fashion as before - so no MQTT protocol…

I got the answer:

Just set the command topic on the broker to rl1c_0/gpio/0 and use payload 0 or 1.

rl1c_0 is unit name,

relay is triggered by gpio0

so i shall be: state_topic: ‘/ESPEasy-Klop-LED/gpio/0’ where 0 is the gpio number.

try and let me know if it worked.

So the code should be:

  - platform: mqtt
    name: ESPEasy Klop - LED senzor (stanje)
    state_topic: /ESPEasy-Klop-LED/gpio/0'
    value_template: >- 
      {% if 'relay,0,0' in value %}   
        {{'OFF'}}
      {% elif 'relay,0,1' in value %}
        {{'ON'}}
      {% endif %}

Or something different way?

I didn’t try on HA yet, but i guess the correct way is:

The configuration will look like the example below:

# Example configuration.yaml entry
switch:
  - platform: mqtt
    name: ESPEasy Klop - LED senzor (stanje)
    state_topic: "ESPEasy-Klop-LED/gpio/0"
    command_topic: "ESPEasy-Klop-LED/gpio/0"
    payload_on: "1"
    payload_off: "0"

anyway, i suggest to try:

mosquitto_pub -h 127.0.0.1 -t ESPEasy-Klop-LED/gpio/0 -m "1" 

and

mosquitto_pub -h 127.0.0.1 -t ESPEasy-Klop-LED/gpio/0 -m "0" 

to make sure it works.

Please let me know if it worked.

I tried but this do not work.

I also tried:

  - platform: mqtt
    name: "Klop - LED osvetlitev (stalna)"
    state_topic: "ESPEasy-Klop-LED/gpio/cmd"
    command_topic: "ESPEasy-Klop-LED/gpio/cmd"
    payload_on: "relay,1,1"
    payload_off: "relay,1,0"

and

  - platform: mqtt
    name: "Klop - LED osvetlitev (stalna)"
    state_topic: "ESPEasy-Klop-LED/gpio/cmd"
    command_topic: "ESPEasy-Klop-LED/gpio/cmd"
    payload_on: "1,1"
    payload_off: "1,0"

and

  - platform: mqtt
    name: "Klop - LED osvetlitev (stalna)"
    state_topic: "ESPEasy-Klop-LED/gpio/1"
    command_topic: "ESPEasy-Klop-LED/gpio/1"
    payload_on: "1"
    payload_off: "0"

So, don’t know if maybe there is just problem regarding configuration on device configuration…

does this works?

if this also does not works, try to change the hostname from ESPEasy-Klop-LED to ESPEasy_Klop_LED or ESPEasyKlopLED.