MQTT Button Automations issues

Hi Everyone, i hope you guys can help me.

I am using a Arduino Mega with Ethernet Shield and some buttons.
MQTT on it aswell.

When i click a button i publish this payload: “20-45” on topic: “buttons”

Its always the same payload, how can i automate that so when i click the button its changing states in home-assistant?

I know the different between pub and sub, but i cant get my head to think of a solution for this, can you guys help?

/DkAutomater

1 Like

Thanks VDRainer, but can i add to a switch or sensor?

Or will it only work in automations?

Its working in a automations, so that is really nice, thanks.

Meaby i will just stick to this.

You can also use the MQTT Binary Sensor if the payload is always the same.

Do you mean like this?:

  - platform: mqtt
name: "MQTT Binary Sensor1"
state_topic: "buttons"
payload_on: "20-44"

With the proper intentation

binary_sensor:
  - platform: mqtt
    name: "MQTT Binary Sensor1"
    state_topic: "buttons"
    payload_on: "20-44"

it should work.

Its change from off to on, but after next button press, its keep on the binary sensor.

And i dont have two payloads, one for on and one for off.

So that will not work.

For this there’s the off_delay option in the sensor.

off_delay
(integer)(Optional)For sensors that only sends ‘On’ state updates, this variable sets a delay in seconds after which the sensor state will be updated back to ‘Off’.

Like this

  - platform: mqtt
name: "MQTT Binary Sensor1"
state_topic: "buttons"
payload_on: "20-44"
off_delay: "1"

Its not working, its keep the state on after 1 click on the button.

What about
off_delay: 1

(integer)(Optional)For sensors that only sends ‘On’ state updates

Does not work with this:

  - platform: mqtt
name: "MQTTBinarySensor1"
state_topic: "buttons"
payload_on: "20-44"
off_delay: 1

The state is off after i reboot the system, when i click the button, the state goes on and keeps on, not going back to off state.

Could you try meaby to see if its only me that have this issue?

binary_sensor:
  - platform: mqtt
    name: "MQTTBinarySensor1"
    state_topic: "home/tests/button1"
    payload_on: "20-44"
    off_delay: 1

Works for me.
Sensor goes to on, 1 second later to off.

Publish with:
mosquitto_pub -h <mqtt_broker> -t "home/tests/button1" -m "20-44"

Does not work for me, its keep the on state all the time.

Very odd.

I created a switch, and i make an automation that change that state of that switch, so i can automate with that switch.

But still odd its not working with the binary sensor.


off_delay was canceled :frowning:
1 Like

I dont use the latest version, so this should not be an issue.

Hello,
if off_delay has been canceled in Nov 2018, is it still relevant to be in the documentation in Feb 2020?

https://github.com/home-assistant/home-assistant/pull/18389

Best regards