I have a SonoffSV flashed with Tasmota and connected to a Reed switch, when the Reed switch is closed it posts the Switch2 state as “ON” when the magnet is removed the Switch2 state goes to “OFF”
I wrote a simple automation that when Reed switch is closed it should send a text as per automation below:
- id: '1612856073957'
alias: Garage
description: 'Send text if garage door opens'
trigger:
- platform: mqtt
topic: stat/tasmota_01/SWITCH2
payload: 'ON'
condition: []
action:
- service: notify.gmail_notification
data:
message: GMail:Garage Door Opended!
title: HA
mode: single
If I manually execute the automation from automation editor, I get the text so GMail notification service is set up correctly. But when I close the Reed switch, I can see with MQTT Explorer that Switch2 state changes to “ON” but the automation does not get triggered.
Please see if you can point me where I might missing something conceptually.
Thanks.
The binary sensor name binary_sensor.garage_door_sensor does shows up but in lovelace UI it is always shown as “unavailable”. And that might explain why the automation below did not work:
- id: '1612924834709'
alias: Garage-02
description: ''
trigger:
- platform: state
entity_id: binary_sensor.garage_door_sensor
from: 'OFF'
to: 'ON'
condition: []
action:
- service: notify.gmail_notification
data:
message: Great news, garage door just opened!
title: Important!
mode: single
Option-2: did not create the binary sensor and just used MQTT topic in automation but this one did not work either:
- id: '1612923798074'
alias: Garage-01
description: Texts when garage door opens
trigger:
- platform: mqtt
topic: stat/tasmota_01/SWITCH2
payload: '{"STATE":"ON"}'
condition: []
action:
- service: notify.gmail_notification
data:
message: PM garage door just opened
title: Important Notice!
This one did not work either, I’ll appreciate if anyone can point out the error or my mistake here.
Thanks.
If you’re running tasmota 9.2 then you can enable SetOption114. This decouples switches from relays and makes device triggers for home assistant automations. You will need to make sure you have switchmode 1 enabled (or any on/off switchmode varients)
Ok, so it turns out that Tasmota device did have “SetOption19 On” when I turned this option off the Mosquitto broker stopped receiving updates from the device. The Tasmota Integration loads without any errors but not creating any sensors for detected devices so the problem may not be with the code above but with the Tasmota setup.
So here is the latest update, I flashed the Tasmota one more time and reverted to my older snapshot of HA to start fresh and followed these steps:
On Tasmota “SetOption19 0” to allow native discovery
Using MQTT Explorer, I could see Tasmota topic created (there were many including one that seemed to have all the configuration of Tasmota in a JSON object)
Added Tasmota integration on HA, and added following code:
Look at the payloads in the mqtt messages you have captured. Are they this?
'{"STATE":"ON"}'
'{"STATE":"OFF"}'
No they are not. Now that you have changed the Tasmota configuration they are ON and OFF. So this is what your payloads have to be set to in your binary sensor. Fortunately for you this is exactly what the default states are:
@tom_l thanks for all your help and finally got to the bottom of it.
The problem was not in HA but at the Tasmota end and I was making a basic mistake in the UI. I manually changed the prefix to “Garage Door” but it seems it messed up MQTT topics queue. As soon as I changed to default values the code above with some modification (for MQTT topic path) started working.
A really good start to the weekend!!
Thanks again.