I’m trying to enhance my automation that I first had based on sunset but I need to tweak it more so it activates a little while before sunset so I did that:
@treno thanks but it’s condition I need, not for a trigger @ih8gates very good idea to go through a variable (sensor in HA terminology) as it can be reused for other automations. I still have an issue to implement it as I added your logic at my configuration file:
sensor:
- platform: template
sensors:
nuit:
friendly_name: 'Mode Nuit'
value_template: >
{% if (states.sun.sun.attributes.elevation | int < 20) %}true
{% elif ( (states.sun.sun.attributes.elevation | int < 30) and (states.sensor.dark_sky_cloud_coverage.state | int > 40)) %}true
{% elif (states.sensor.dark_sky_cloud_coverage.state | int > 80) %}true
{% else %}false
{% endif %}
Is it normal that the variable has unknown state in States tab ?? Isn’t it evaluated at startup of HA ?
I then modified my automation with that code now:
- alias: Lecture PMP
trigger:
- platform: state
entity_id: media_player.pmp_salon
to: 'playing'
from: 'idle'
condition:
- condition: state
entity_id: sensor.nuit
state: true
action:
service: scene.turn_on
entity_id: scene.Salon_cinema
but it complains about:
2017-07-10 16:50:34 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘state’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 219). Please check the docs at Automation - Home Assistant
so a little lost here for now