Hello,
Here’s the thing; I’d like to set light brightness based on time in an automation.
## Motion sensor wc
- alias: WC Lights off when motion off
trigger:
- platform: state
entity_id: binary_sensor.wc_pir
to: 'off'
for:
minutes: 8
action:
- service: light.turn_on
data:
entity_id: light.wc_ylavalo
brightness: 0
- alias: WC Lights on when motion on
trigger:
- platform: state
entity_id: binary_sensor.wc_pir
to: 'on'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.light.wc_ylavalo.attributes.brightness < 5 }}'
- condition: numeric_state
entity_id: sensor.wc_ldr
below: 100
action:
- service: light.turn_on
data:
entity_id: light.wc_ylavalo
brightness: >-
{% if now().strftime('%H')| int >= 22 %}
100
{% elif now().strftime('%H')| int < 7 %}
10
{% elif now().strftime('%H')| int >= 7 %}
255
{% endif %}
I get the following error when triggering the automation above:
Invalid service data for light.turn_on: expected int for dictionary value @ data['brightness']. Got "{% if now().strftime('%H')| int >= 22 %}\n 100\n{% elif now().strftime('%H')| int < 7 %}\n 10\n{% elif now().strftime('%H')| int >= 7 %}\n 255\n{% endif %}"
The automation works fine without the if-elif-else block.
Any help is appreciated!
Br,
Mikko