I am attempting to create an automation that turns on some lights when it becomes overcast outside (only during the day). I am using the Dark Sky component and I am currently using the dark_sky_cloud_coverage sensor for the automation trigger. This attribute can have some odd peaks at times, so I want to only trigger when it has been above 70% for the last three polls (polling every 10 minutes). I have attempted to add a “for” statement in the trigger and in the condition. Both return errors in the log file. Here is the automation:
- alias: 'Overcast Lights On'
trigger:
platform: time
minutes: '/10'
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.dark_sky_cloud_coverage
above: 70
for:
minutes: 29
- condition: sun
after: sunrise
before: sunset
action:
- service: scene.turn_on
entity_id: scene.fade_in_to_bright
- service: notify.PushBullet
data:
message: 'Overcast lights are now on'
And here is the error I receive:
17-01-06 11:33:15 homeassistant.bootstrap: Invalid config for [automation]: [for] is an invalid option for [automation]. Check: automation->condition->0->conditions->0->for. (See C:\Users\Ryan\AppData\Roaming\.homeassistant\configuration.yaml:291). Please check the docs at https://home-assistant.io/components/automation/
Can anyone point me in the right direction to resolve this?
Can’t use for with numeric states like that. The way around it is to create a template sensor for the state your monitoring and then use the state condition on THAT sensor with the for.
I ran into the same issue with my Washing machine notifications automation and that’s how I got around it.
I have completely reworked this automation and I am now having a different issue. I am using the new Threshold Binary Sensor to set the Overcast state (‘on’ when cloud_cover is above 69). This appears to be working, however I am getting the notification every 11 minutes. I want this to only trigger ONCE after the ‘Overcast’ sensor has been ‘on’ for more than 11 minutes.
(I am polling the dark_sky sensor every 10 minutes, so I am using 11 minutes to ensure I have values for the last two polls)
For the last few days I’ve been trying to figure out how to store stuff inside of HomeAssistant. Booleans seem like the best way to store things as long as it’s on/off.
I’m also most likely going to be using MQTT to set temporary values so that I can keep the lights on the same brightness after an event. But booleans are way simpler and in your case work just fine.
I used the recommendation from @cdaoust and it is finally working!! I had a small rain shower move in this morning just before sunrise. Once the sun was up, the action was triggered because it was still more than 70% cloud coverage. And I didn’t receive a notice every 11 minutes after it fired the first time. A few hours later, the clouds cleared and the overcast lights were turned off and I received that notification only once as well.
I’ve implemented this because, as you say, sometimes when it’s overcast you need the lights on. But sometimes, like today, the cloud coverage is 84% but it’s still lovely and bright, so I don’t need the lights on but they came on anyway.
I was thinking to add maybe precipitation probability (or something?) as an extra condition, as today it is 0% (so the clouds aren’t dark, so even though there’s lots of cloud it is light, whereas if the clouds were dark because it was going to rain I would probably need the lights on right now).
No, I had a fleeting thought about it, posted the above message and then forgot all about it tbh!
I was looking at sun angles and rain likelihood and various ideas but didn’t come up with anything specific for an algorithm. I’ve been redecorating the house so a lot of my lighting automations are switched off so I’ve not thought about it. I guess I’ll come up with something at some point
I’m trying to combine the ideas above and to not use the input boolean. so my yaml looks like this:
sensor:
- platform: darksky
api_key: [hidden]
monitored_conditions:
- summary
- icon
- cloud_cover
- wind_speed
- apparent_temperature
binary_sensor:
- platform: threshold
name: Overcast
threshold: 79
type: upper
entity_id: sensor.dark_sky_cloud_coverage
automation old:
- alias: 'Overcast Lights On'
trigger:
- platform: state
entity_id: binary_sensor.overcast
state: 'on'
for:
minutes: 2
condition:
condition: and
conditions:
- condition: sun
after: sunrise
before: sunset
- condition: state
entity_id: light.living_room
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: device_tracker.Bob
state: home
- condition: state
entity_id: device_tracker.Alice
state: home
action:
- service: scene.turn_on
entity_id: scene.livingroom_fadeon
- service: notify.PushBullet
data:
message: "It looks rather cloudy so I've put some lights on"
I’m pretty sure the scene is okay as I use it other automations and I use the sun conditions elsewhere too. I can see the light.living_room is showing as off and I can see the binary sensor is tracking the cloud condition. However the lights do not come on.
I’ve tried removing the presence tracking conditions to test and that doesn’t seem to help.
I’m sure I am missing something obvious and would appreciate any pointers.
I found the could_cover sensor to be too variable for me. Maybe it’s just where I live, but it would jump from 30% to 90% and back down to 20% in a short amount of time quite regularly. So, I ditched the idea after my wife started complaining about the lights going on and off throughout the day.
So instead, I built Ben’s $15 multisensor and then wrote some automations around the light-level sensor. I have to say I’m much happier with the results. Basically it turns the lights on when there is motion in the room and the light level is below a certain point. Here’s what I’ve done:
binary_sensor:
- platform: threshold
name: Man Cave Light Level
threshold: 250
type: lower
entity_id: sensor.multisensor_light_level
automation:
- alias: 'Man Cave Lamp Motion'
trigger:
platform: state
entity_id: sensor.multisensor_motion
to: 'motion detected'
condition:
condition: and
conditions:
- condition: state
entity_id: light.man_cave_lamp
state: 'off'
- condition: state
entity_id: binary_sensor.man_cave_light_level
state: 'on'
action:
service: scene.turn_on
entity_id: scene.man_cave_on
- alias: 'Man Cave Lamp No Motion'
trigger:
platform: state
entity_id: sensor.multisensor_motion
to: 'standby'
for:
minutes: 30
condition:
condition: and
conditions:
- condition: state
entity_id: light.man_cave_lamp
state: 'on'
- condition: state
entity_id: sun.sun
state: 'above_horizon'
action:
service: scene.turn_on
entity_id: scene.man_cave_off