I’ve got an automation to turn my lamps on when the cloud coverage reported from dark sky goes above 49% and it’s before sunset or after sunrise. For some reason this automation is never triggered when the sensor goes above 49%. I suspect the problem stems from the conditions. There are no related errors in the log. Any ideas? The automation looks like this:
- id: Lamps_on_when_cloudy
alias: Lamps on when its cloudy
initial_state: True
hide_entity: False
trigger:
- platform: numeric_state
above: 49
entity_id: sensor.dark_sky_cloud_cover
action:
service: homeassistant.turn_on
entity_id: group.all_lamps
condition:
condition: and
conditions:
- condition: sun
after: sunrise
- condition: sun
before: sunset
If I’m not mistaken, triggers will only happen the first time that the value crosses the threshold amount. Are you seeing the cloud cover go from below 49 to above? Or is it already above 49 when you start HA? Have you tried the code without the conditions to rule out an issue there?
I use Dark Sky, combined with some other elements, to create a binary sensor that answers the question “Is it dark enough that I should probably turn on a light?” Then I use that sensor as a trigger for my automation.
sensor:
- platform: template
sensors:
turn_on_indoor_lights:
friendly_name: 'Turn On Indoor Lights'
value_template: >
{% if (states.sun.sun.attributes.elevation | int < 30) %}true
{% elif ( (states.sun.sun.attributes.elevation | int < 40) and (states.sensor.dark_sky_cloud_coverage.state | int > 50)) %}true
{% elif (states.sensor.dark_sky_cloud_coverage.state | int > 90) %}true
{% else %}false
{% endif %}
and the automation:
- alias: Turn on indoor lights based on darkness
trigger:
- platform: state
entity_id: sensor.turn_on_indoor_lights
to: 'true'
from: 'false'
action:
- service: scene.turn_on
entity_id: scene.indoor_auto_on
- service: notify.scott_notifier
data_template:
message: "Auto indoor lights. Sun angle is {{states.sensor.solar_angle.state}}."
- alias: Turn off indoor lights based on darkness
trigger:
- platform: state
entity_id: sensor.turn_on_indoor_lights
to: 'false'
from: 'true'
action:
service: scene.turn_on
entity_id: scene.indoor_auto_off
Thanks for the reply! Yes, this morning the cloud coverage sensor was in the ~20s, it went up to the ~70s as the day went on without the automation being triggered. I do think the issue has to do with the conditions, but I’m not sure how those simple conditions could be causing this problem.
I like the way you’ve set this up using a sensor, I might try that if I can’t get my current method to work.
No, I sometimes use multiple conditions as well, and the ones you used look okay. Another problem could be the value extraction from the sensor. Check this to use a value_template.
On a second look, am I wrong or does this automation trigger on every state change above 49, even if the lights are already on, in this case either add another condition or use a sensor setup similar @ih8gates.
Yes, this does not check to see if the lights are already on, if that’s what you mean. And I don’t know, I assume this just triggers as soon as the sensor value goes above 49.
Also, I’m not sure how to overwrite a sensor value. Would this be a “customization”?
Thanks. After setting it to a value below 49 it then updated to the current actual value pretty quickly afterward, which is 71. The automation did not trigger. So maybe it is the value extraction problem.