Hello Community i am really new to HA and search here for help.
My Name is Daniel and i am Happy to be here.
Iam using an RPi3+ with an Raspeeshield and a manually installed Homeassistant(not HASSIO)
i played around and everything works really fine and easy but i have a problem and couldnt solve it.
I have an Aquara door sensor and he works, now i want when my “stehlampe” is on and somebody opens the door than the stehlampe switch off. And this works but i also want that when the door gets closed the light should switch back to on and this didnt work.
entity_id: binary_sensor.openclose_5
platform: state
condition:
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
action:
Could you please apply proper formatting to your code snippet so that it is displayed as it is in your yaml-file - for instructions see the blue box at the top of the page.
As suggested you really need to properly format your YAML code, otherwise it makes if very difficult to read, and also indentation errors are impossible to see.
You didn’t say, but I’ll assume that binary_sensor.openclose_5 being ‘on’ indicates the door is open, and being ‘off’ indicates the door is closed. (That’s the typical meaning. See Binary Sensor Device Class for more detail.)
I would recommend using the light.turn_on and light.turn_off services for this instead of light.toggle. If the light got turned on or off by some other means, then this automation would get “out of sync” using toggle.
Also you didn’t mention in your description of how you want this automation to work anything about time of day, but it looks like that matters based on your current automation.
So, putting everything together, I would suggest this:
- id: '1534705610002'
alias: Insektenschutz
trigger:
platform: state
entity_id: binary_sensor.openclose_5
condition:
condition: state
entity_id: sun.sun
state: below_horizon
action:
service_template: >
# If door opened, turn light off.
{% if trigger.to_state.state == 'on' %}
light.turn_off
# Else door closed, so turn light on.
{% else %}
light.turn_on
{% endif %}
entity_id: light.stehlampe
This automation will trigger whenever binary_sensor.openclose_5 changes, and the action will run at that time if it’s after sunset or before sunrise (i.e., the sun is down.) The service_template determines which service to run. It will turn the light off if binary_sensor.openclose_5 just changed to ‘on’ (i.e., the door opened.) Otherwise it will turn the light on (i.e., the door closed.)
Wow thx for help. O will try this tomorrow.
Yes i tryed to use the code component for the topic bit i do not really understand how this works. Also the held didnt help me hahaha i am so sorry about that
If you’re not getting an error now, then removing those two lines should not cause an error. If you do get an error, though, post it and it might give a clue what’s wrong. Good luck!
Hey so now i had time to test it but its not perfect.
The light turn on and off if sun is down.
But its always turns on and off also if the light was not turned on before
This automation will only run when the door opens while the light is on and it’s dark. It will turn the light off, wait for the door to close, then turn the light on.