Hey everyone. I have a question for all you Tasmota experts.
First some background:
I have my garage door set up with a sonoff basic & Tasmota, which can open and close the door when the relay is activated, and sense the door state with a reed switch attached to GPIO14. The open/close mechanism is basically just a toggle on the garage door opener when you bridge two contact points, so I have tasmota set to open the relay 1 second after it is closed. That all works as intended.
Now the problem:
In home assistant, I have a “cover.garagedoor” set up with “platform: mqtt”, but home assistant doesn’t seem to distinguish whether or not the door is already closed when calling “cover.close_cover”. Because the MQTT commands for opening and closing the door are both the same (close the sonoff’s relay), this manifests as me saying “Hey google, close the garage door”, and the garage door then opening.
My question:
Is there a way to make tasmota listen to different MQTT commands under different circumstances? Right now it would listen for “cmnd/GarageDoor/POWER ON” and “cmnd/GarageDoor/POWER OFF”. I would like it to pehaps listen for “cmnd/GarageDoor/OPEN” (but ignore this if GPIO14 is not grounded, i.e., the door is already open) and “cmnd/GarageDoor/CLOSE” (but ignore this if GPIO14 is grounded, i.e., the door is already closed) and then in the background send itself the POWER ON command when required.
Hopefully that all makes sense. I believe there is a way to accomplish this with Tasmota’s rules, but I am far from well-versed in their usage. Can anybody help?
I have a similar set up but I don’t use MQTT. I use zwave stuff. But in the end it is functionally the same.
Here are the code snippets for how I operate my garage doors:
automation:
- alias: Toggle North Garage Door Switch
trigger:
platform: state
entity_id: switch.garage_door_north_operator_switch
to: 'on'
for:
seconds: 1
action:
service: homeassistant.turn_off
entity_id: switch.garage_door_north_operator_switch
cover:
- platform: template
covers:
north_garage_door:
friendly_name: 'North Garage Door'
value_template: "{{ is_state('binary_sensor.garage_door_north_position_sensor', 'on') }}"
open_cover:
service: script.turn_on
entity_id: script.open_gdn
close_cover:
service: script.turn_on
entity_id: script.close_gdn
stop_cover:
service: switch.turn_on
entity_id: switch.garage_door_north_operator_switch
icon_template: "{% if not is_state('binary_sensor.garage_door_north_position_sensor', 'off') %}mdi:garage-open{% else %}mdi:garage{% endif %}"
script:
close_gdn:
alias: Close the North Garage Door
sequence:
- condition: state
entity_id: binary_sensor.garage_door_north_position_sensor
state: 'on'
- service: switch.turn_on
entity_id: switch.garage_door_north_operator_switch
open_gdn:
alias: Open the North Garage Door
sequence:
- condition: state
entity_id: binary_sensor.garage_door_north_position_sensor
state: 'off'
- service: switch.turn_on
entity_id: switch.garage_door_north_operator_switch
Then in my Alexa app I have a routines set up that calls the scripts to open and close the door.
So if I say “Alexa, open the north garage door” it triggers the script to open the door which checks that the door is closed before toggling the garage door operator switch.
And since I use those same scripts in the open_cover/close_cover then that prevents me from, for example, “opening” the door if it’s already open (which would then close it).
If you feel it’s deserved then give it a “solution” tick mark. That way others see that it’s solved and move on or if they have the same question they can know to check it out.
Here’s my solution, I based my template off of my previous MQTT cover. I also found I didn’t need the scripts, I could just use the body of the script in the template actions for the new cover. I didn’t need the automation because I configured Tasmota to make the sonoff’s relay open again after 1 second. Renamed my old garage door entity, and named the new one what the old one used to be. No other actions needed to be changed.
I have the same setup but i’m having an issue with recording the sate of the sensor in home assistant. like if i restart home assistant the state of the sensor becomes unknown. then if i set retain to on, the door will open automatically when i restart home assistant. can you please share with us the console command to decouple the relay from the sensor switch and how to retain (only) the sensor status in home assistant?
Do NOT set retain in home assistant. What you want to do is set “SwitchRetain on” in Tasmota.
The retain flag in Home Assistant makes the MQTT topics that HA sends be retained by the broker – that’s the command topics to open or close the door. “SwitchRetain on” on the Tasmota side will make the topics that Tasmota sends for the state of the switch be retained by the broker. This will allow HA to pick up the state of the switch (whether your door is open or closed) on restart.
In my experience, you almost never want to set “retain: true” in HA.
First, set the PulseTime for the device, which you can do via MQTT using the command
cmnd/[Topic]/PulseTime 10
You only have to do this once.
Then, whenever the device is turned on, it will automatically turn off after the delay configured by PulseTime. State information is sent by the device over MQTT on the
stat/[Topic]/POWER
topic, so you can tell whenever it’s turned on on off.
Hate to bring this one back from the dead, but when I set the PulseTime on my Sonoff 4ch Pro R3, it only sets it for the first relay. How do I do that for the other ones? So far I’ve only been able to get the PulseTime setting to work via the console. MQT shows Command Unknown.
I haven’t tried this myself, because I only have one relay on my device, but going with the paradigm of other TASMOTA commands, you could try PulseTime1, PulseTime2, etc.
With “cover.west_door_west_door” for door ID"
And “binary_sensor.west_door_switch2”
Where do I put these in the code above?
I will have 3 garage doors to start with and I am not sure if I need 3 copies of each, meaning 1 each cover and MQTT?
Thanks in advance.