Help Needed:
In action block, create template with if-then logic to select appropriate scene based on time of day.
Background:
Newbie running HA ion a raspberry pi. Yes, I’ve spent hours searching and trying solving my own problem.
Goal:
Automate lights to turn on one of two scene-based brightness based on time of day, sun angle, and occupancy.
Trigger:
Occupancy reported
Condition:
Sun below 10 degree
Action:
If time < 9 PM, then turn on scene.evening_interior_lights_on
If time > 9 PM, then turn on scene.evening_interior_lights_dim
Current Code:
alias: Evening Lights On (Occupancy and Sun Angle)
description: ''
trigger:
- type: occupied
platform: device
device_id: 7d2e97ba53cdb2245fb66fe5fee3c43f
entity_id: binary_sensor.living_room_occupancy
domain: binary_sensor
- type: occupied
platform: device
device_id: b9b03853cb63626bd2ab51747c47b861
entity_id: binary_sensor.main_floor_occupancy
domain: binary_sensor
condition:
- condition: numeric_state
entity_id: sun.sun
attribute: elevation
below: '10'
action:
data_template: >-
{% if (states.sensor.time.state <= 21:00) %}
entity_id: scene.evening_interior_lights_on
{% else %}
entity_id: scene.evening_interior_lights_dim
{% endif %}
service: scene.turn_on
mode: single
Error Message:
Message malformed: extra keys not allowed @ data[‘action’][0][’-data_template’]