I know I am missing something simple but I am dumbfounded to find out what is missing. Trying to get the fan of the specific XiaoMi Air Purifier (I have 4 here) to turn on when its sensor has breached its threshold. No problem in writing 2 automation to achieve what I need but trying to consolidate into 1 instead.
alias: "Air Purifiers Bad AQI State Change"
description: ""
trigger:
- platform: state
entity_id:
- sensor.jtr_mi_air_purifier_3c_pm2_5
- sensor.ctr_mi_air_purifier_3c_pm2_5
- sensor.mbr_mi_air_purifier_3c_pm2_5
- sensor.lvr_mi_air_purifier_3c_pm2_5
id: Bad_AQI_Change
condition: []
action:
- service: >-
fan.turn_{{ 'on' if states("{{ trigger.entity_id }}") | int > 12 else 'off'
}}
data: {}
target:
entity_id: "{{ trigger.entity_id|replace('sensor', 'fan')|replace('_pm2_5', '') }}"
mode: single
Nothing wrong with the target but the exception is thrown at the service level (fan):
Error: Error rendering service name template: ValueError: Template error: int got invalid input âunknownâ when rendering template âfan.turn_{{ âonâ if states("{{ trigger.entity_id }}")|int > 12 else âoffâ }}â but no default was specified.
Any advice on how to unblock this ? Thank you !