I have trouble, my automation with service_temlate not working
In logs i see error: Error while executing automation automation.bedroom_switch_light2: Template rendered invalid service.
- alias: bedroom_switch_light2
trigger:
- platform: state
entity_id: sensor.0x00158d000170d9eb_action
to: 'single_right'
action:
- entity_id: light.xiaomi_philips_smart_led_ceiling_lamp
service_template: >
{%- if states('sensor.ph_lamp_bedroom_brightness') | float >=1 and states('sensor.ph_lamp_bedroom_brightness') | float < 56 -%}
xiaomi_miio_philipslight.light_set_scene
{% endif %}
data_template:
scene: 2
You don’t have an else case for when your if statement is not true. This gives a null service → error.
If you don’t have another service to run when the if test is not true then don’t use a service template.
Put the test as a template condition (or use numeric state conditions) and just put your service in the actions. It won’t run if the conditions don’t pass.