h4nc
January 19, 2019, 6:38pm
1
My mqtt based door switch goes to open and close when I reboot home assistant.
I have an automation that is triggered when the door goes from open to close.
So when I restart ha the automation is triggered, which is not wanted.
I think it has something to do with the retain flag.
So I tried to set up retain at my tasmota device with powerretain 1
but this also did not help. So I changed it back and tried to set retain
to true
in the switch.yaml
file.
This also did not work.
So how can I stop that the state of the door goes to open and close at a restart? What causes this? The door is closed during the restart.
123
(Taras)
January 19, 2019, 6:53pm
2
Post the relevant portion(s) of your configuration.yaml
file so we can get some clues to what’s causing this problem.
h4nc
January 20, 2019, 2:16pm
3
Of course here is my config:
This is my automation (automation.yaml):
- alias: Light- door trigger
initial_state: 'on'
trigger:
- platform: state
entity_id: cover.door
from: 'open'
to: 'closed'
for: '00:00:02'
action:
in cover.yaml
- platform: template
covers:
door:
value_template: "{{ states.binary_sensor.door_state.state == 'on' }}"
close_cover:
service: homeassistant.turn_on
data:
entity_id: script.door_script
open_cover:
service: homeassistant.turn_on
data:
entity_id: script.door_script
in binary_sensor.yaml:
- platform: mqtt
name: "door_state"
state_topic: "stat/sonoff_door/RESULT"
value_template: '{{ value_json["POWER1"] }}'
force_update: true
device_class: garage_door
123
(Taras)
January 20, 2019, 2:56pm
4
Actually, it’s desirable to publish state topics with retain=true. So if the sonoff is publishing its status as a retained message, that’s fine.
Try this: remove force_update: true
then restart Home Assistant. Let us know if the automation continues to be triggered.
h4nc
January 20, 2019, 4:08pm
5
Looks like I already solved the problem.
Ididn’t tell that the above could is already my second version.
Before I had a mqtt sensor (not binary) to extract the data and a binary template sensor so look for that sensor and go on and of.
With a little more experience than at the beginning (when I set up this automation) I know direclty use an mqtt binary sensor to extract that data.
Fun thing… I tried deleting force_update: true
but this will again trigger the automation. Going back and it works.
In my second version (code in my last post) I also changed the the code of cover a little bit.
Instead of this
value_template: "{{ states.binary_sensor.door_state.state == 'on' }}"
I had something that looked like this
value_template: "{{ is_states(sensor.door_state) }}"
So maybe that makes the difference.
h4nc
January 20, 2019, 5:16pm
6
I was wrong, the automation still gets triggered but it seems like it does not every restart.
123
(Taras)
January 20, 2019, 5:24pm
7
I don’t know what to tell you. Based on what you wrote, I no longer understand what you do or don’t currently have in your configuration.
All I can tell you is that this:
value_template: "{{ states.binary_sensor.door_state.state == 'on' }}"
and this:
value_template: "{{ is_states(sensor.door_state) }}"
are not referring to the same entity.
binary_sensor.door_state
is a different entity from sensor.door_state
. You’ve only shared the config for the binary_sensor
so it’s impossible for anyone to comment on how sensor.door_state
behaves.
Good luck finding a solution to the problem.
h4nc
January 20, 2019, 5:47pm
8
I know that. The code that you can find above is the current code I use.
Before I had a sensor and a binary sensor. Now I ony use one binary_sensor.
I hope I fill still get suggestions on how to solve this based on the code above:
Of course here is my config:
This is my automation (automation.yaml):
- alias: Light- door trigger
initial_state: 'on'
trigger:
- platform: state
entity_id: cover.door
from: 'open'
to: 'closed'
for: '00:00:02'
action:
in cover.yaml
- platform: template
covers:
door:
value_template: "{{ states.binary_sensor.door_state.state == 'on' }}"
close_cover:
service: homeassistant.turn_on
data:
entity_id: script.door_script
…