How to configure impulse button for mqtt?

Hello I will have a bunch of impulse button.

I think I might have 2 scenario

  • When ewer a button is pushed need to toggle there state. (I not 100% sure this will need may be not necessary)
  • Group some of them together (like living_room_light ) when ewer a click received from any of the switch change the living_room_light.

I wonder how the config need to look like?

You need an automation triggered by the mqtt message.

Hello,
Thank you for your help.

So if i understand well i need to do a following:
1. define a sensor (not sure if it is need)
> sensor Test_6:

platform: mqtt
state_topic: "ESP_001_test/5"
name: "Kapcsolo_1"
#payload_on: '1'
#payload_off: '0'

payload_on and payload_off not need because the sensor will only send a “Clicked” message

2. configure the automation:

automation:
  trigger:
    platform: mqtt
    topic: ESP_001_test/5
    # Optional
    # payload: 'on'

only need to subscribe to topic: ESP_001_test/5 and not need to check payload

That looks correct. You do not need the sensor. You only need to check the payload if it will be different in some way for different actions.

It is working, but not 100% properly.

- id: vk_1
  alias: "When any button clicked change led1 state"
  initial_state: true
  trigger:
    platform: mqtt
    topic: ESP_001_test/7
  action:
    service: switch.toggle
    entity_id: switch.Test_2

Around every 10th switching is missed :frowning:
i see in my ESP the MQTT message was sent out.
The led state and Test_2 state is consistent.

that mean my automation not triggering the state change sometimes. :frowning:

You see the esp tried to send the message. That is no guarantee that the broker received it. Try subscribing to the topic with mosquitto_sub to check if the message was received at the broker.

If you are getting missing messages, try setting qos=1, which adds some checking to ensure the message gets sent at least once. But then, it may get sent twice which will have the same effect.

Setting qos=2 would be ideal, but I don’t know of an esp library that suports that :unamused:

It looks like ESP library dose support QOS 2 :slight_smile:
only question is how can i put qos=2 in my automation trigger?

  trigger:
    platform: mqtt
    topic: ESP_001_test/7
    qos: 2

dose not work :frowning:

You would need to set the qos level on the esp.