I am sorry, I don’t mean to come across as lazy, but I am just plain tired from fighting YAML. I have been trying to get this automation working and between hunting down spaces that are not there, yet should be, and errors in the log that don’t point to some syntactical issue I’m just about fried. Sorry HA developers and contributors, I absolutely love your platform, but without question, they choice for configuration language (in my opinion) sucks.
At any rate, I am trying to learn and I keep getting thwarted by the documentation examples that seem to have no basis in reality (I have yet to follow one that has worked). I put together the below automation. I have two conditions:
It must be 30 minutes before sunset
AND the back door must be open
These conditions being met, I want to turn on two light (for when we let the dogs out). Then, when the back door is closed, turn the lights back off. Just don’t turn them on when the door opens unless it is 30 minutes before sunset.
I haven’t gotten to the turn off part simply because I have fought just getting the lights to turn on.
automation:
- alias: Backyard Auto Lights ON
trigger:
platform: sun
event: sunset
offset: "-00:30:00"
condition:
condition: state
entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_47_0
state: 'on'
action:
service: switch.turn_on
entity_id:
- switch.ge_12722_onoff_relay_switch_switch_42_0
- switch.ge_12722_onoff_relay_switch_switch_43_0
In addition to all that I am also seeing the below error in the logs:
homeassistant.core: Unable to find service switch/turn_off
Does anyone have any ideas on that or should I start a new post and see what we can figure out?
First, I feel like your trigger and your conditions are reversed. The door opening should be the trigger. The period before sunset should be the condition for your actions. In addition, you want it to run either anytime AFTER sunset or 30 minutes BEFORE sunset, so you should have both conditions in there, like this:
condition:
condition: sun
after: sunset
after_offset: "-00:30:00"
Secondly I don’t think you can specify multiple entities like that though I can’t find anything in the docs either way. I would consider doing it like this:
Geeee, I am beginning to really, really not like the documentation here because it is hard to know whether or not I can trust it for accuracy or for being current. The documentation does not even mention that with that which covers conditions.
I think I tried reversing them (triggers and conditions) but am not sure. However, I will certainly test it again with your suggestions and see if it works. Thank you for your help.
I saw it, it live updated in fact. I would have NEVER figured out the two after sunset parameters. That’s not even hinted at in the documents. I shall be back shortly with an update once I try your suggestions.
- alias: Back Yard Auto Lights ON
trigger:
platform: state
entity_id: binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_47_0
state: 'on'
conditon:
platform: sun
after: sunset
after_offset: "-00:30:00"
action:
- service: switch.turn_on
entity_id: switch.ge_12722_onoff_relay_switch_switch_42_0
- service: switch.turn_on
entity_id: switch.ge_12722_onoff_relay_switch_switch_43_0
And I got this error in the logs after reloading the automation from HA and that pop up card alerting me to an invalid config:
16-12-26 22:02:29 homeassistant.bootstrap: Invalid config for [automation]: [conditon] is an invalid option for [automation]. Check: automation->conditon. (See /home/hass/.homeassistant/automations.yaml:5). Please check the docs at https://home-assistant.io/components/automation/
When I went to bed last night, the automation I had posted above was working, the lights came on when the door opened and went back off when the door was closed. I get up this morning, now it doesn’t work. I can see that the door sensor is working and that HA is changing states from off to on for that sensor, but the lights are doing nothing. No errors in HA, when I reload the automation file there is no errors, ugggg.
@omeasire thank you for that code, I like that a lot as it is the on and off sequence in one bit of code. Given the issue this morning mentioned above, I will try that out and see if anything changes. I can’t possibly imagine what changed in just a few hours so as the automation to not work.
Maybe this is the reason why your automation didn’t work in the morning.
In that case you may try to check the state of sun sensor (above/below_horizon) in condition.
Also, are you sure that your switches should report their state?
@omeasire, thank you for that link. And yes, the switches do report their state and have with every automation system I have used. I have never known them not to, at least as far as I have observed.
I guess the next question would be can you do offsets from that? It’s not an absolutely huge deal, but I like being able to turn the lights on shortly before sunset and back off slightly after.
Wow, I like the way you think. Though I don’t actually need the lights on, or to come on with the door being opened before sunset. All the lights are LED lights including the yard flood lights so it would not be a big spot on the bill if they should turn on every time the door was opened.
However, the idea of checking the automation each time Home Assistant is restarted is just plain brilliant. I did not know that could be done. I had a very practical use for that yesterday and did not know how to go about doing it so I ended up doing so manually.
automation:
# Change the light in the kitchen and living room to 150 brightness and color red.
trigger:
platform: sun
event: sunset
action:
service: homeassistant.turn_on
entity_id:
- light.kitchen
- light.living_room
data:
brightness: 150
rgb_color: [255, 0, 0]