My problem is simple, but I can’t find any documentation about it:
I have a binary door sensor attached to a door which can be opened through a switch (switchbot), or manually.
The correct state of the door (on/off) is on binary door sensor, not on the switch.
So I need a way to change the state of a switch without execute the command, associating the switch state (on/off) according to the door sensor.
If I understand you correctly this can be done with an automation. Trigger on the binary sensor (any state), set the switchbot switch with an action template dependant on the ‘trigger to state’. If you list your switch and sensor entity_ids I can give you an example.
I have a NEO Door/window sensor (named binary_sensor.027_closet_lr_sensor attached to a closet door and a light inside the closet (named light.l_lr_closet) that is supposed to turn on/off when the door is open/closed - guess that’s pretty much the same as you’re trying to make.
The code is:
- alias: "L-Closet Living Room: Door open"
trigger:
- platform: state
entity_id: binary_sensor.027_closet_lr_sensor
to: 'on'
action:
- service: light.turn_on
entity_id: light.l_lr_closet
- alias: 'L-Closet Living Room: Door closed'
trigger:
- platform: state
entity_id: binary_sensor.027_closet_lr_sensor
to: 'off'
action:
- service: light.turn_off
entity_id: light.l_lr_closet
I think the confusion might be the fact that you are trying to “fake out” the state of the switch based on the current state of the door sensor.
If I can ask…What is the true state of the switch when the door is open? Obviously the state of the switch doesn’t already follow the state of the door or you wouldn’t be asking.
Wouldn’t it make more sense to show the true state of the switch (on/off) but then just display the state of the door separately?
If you really need to show the switch state to follow the state of the door sensor the closest I can think would be a template switch. But even then the command_on & command_off are required (I think) so even then if you click on the switch then it will still act strangely compared to a “real” switch.
Imagine the door can be opened by anyone (it is a garage door). I use a switchbot in order to press a controller to open. After 1 minute the door closes automatically, but the switchbot’s state is still on.
I want to use a binary sensor in order to get the correct state (opened/closed) and set it to the switchbot state.
That means it’s talking to the device, and getting the state from there, but the switchbot does not have any state stored. I think I need to close this case and open to developers another…
I will keep it for a couple of days if someone knows the solution in here.
You have a garage door opener that uses either a remotely operated switch or a locally operated operator of some kind (manual, whatever).
Does the switch require to be kept on when the door is open? IOW, if the switch is on (because you previously used it open the door) and then someone manually closes the door and then you turn off the switch does the door do anything at that point? Does it stay closed or will it open back up?
The reason for the questions is that I also have a garage door opener that uses both a remotely controlled switch thru HA and also RF remote control that came standard with the door. HA can know that the door is opened by another door sensor in a similar way to the way yours works.
The door switch controlled by HA only has to be a momentarily operated switch (like a regular pushbutton). So the way I handle that is that when I activate the switch from HA to open the door then I have an automation that turns the switch back off in one second.
I really don’t care, per se, what the state of the switch is I only care if the door is open or closed. But I do “kind of” care what the state of the switch is but only for completeness sake if you understand me. If the switch state shows “off” but it is in reality “on” then I can see things getting confusing.
Maybe your situation is the same as mine and this might help you think of it in a different way.
Or I’m completely off base and would need additional information to help more.
Ok, You are good
Yes if my switch is on and someone closes the door (actually it closes after 1 min or so automatically), the switch is remaining on.
The work around with the automation it could be ok, IF you can turn the switch back off without pressing it. If you really press the button when the door is closing it will stop and it will remain semi-open which is the worst case scenario…
To minimize confusion I’m going to call the actual normal garage door operator pushbutton the “GDO” and the HA controlled button the “switchbot”
Looking at the switchbots I think they only act as kind of a “virtual finger” pressing the GDO button just like you would when you operate the GDO.
So (and correct me if I’m wrong…) when you normally push the GDO you only momentarily push it then immediately release it. If you turn on the switchbot then turn it back off right away doesn’t it just “unpress” the GDO just like you pulling your finger away from the GDO?
Or does your GDO need to be held in position until the door goes all the way closed or open?
I know the way my GDO works is if I push the button momentarily the door operates (open or closed). But if it’s opening and is half way open and I push the GDO again it stops opening and stays in that position. And if it’s going closed and I push the GDO again it stops and goes back open.
It suits to my case!
The problem I have now is that the valid values for value_template are: open / true or closed / false and the binary sensor returns on/off, should I give a try with these values or there is a way to transform them to open/closed ?
One of the examples has the following, should I try it? value_template: "{{ states('sensor.garage_door')|float > 0 }}"