i got this error message like below.
Error while executing automation automation.dust_airpurifier_onoff. Invalid data for call_service at pos 1: required key not provided @ data[‘message’]
But it works. and it seems that this is from some incorrect indemtation. is it correct? and plz let me know correct script.
- alias: Dust_airpurifier_ONOFF
initial_state: True
trigger:
- platform: template
value_template: "{% if states.sensor.pm10_1.state | float > 20 or states.sensor.pm10_2.state | float > 20 or states.sensor.pm25_1.state | float > 20 or states.sensor.pm25_2.state | float > 20 %} true {% endif %}"
- platform: template
value_template: "{% if states.sensor.pm10_1.state | float < 10 and states.sensor.pm10_2.state | float < 10 and states.sensor.pm25_1.state | float < 10 and states.sensor.pm25_2.state | float < 10 %} true {% endif %}"
action:
- service: notify.telegram
data_template:
message: >
{% if states.sensor.pm10_1.state | float > 20 or states.sensor.pm10_2.state | float > 20 or states.sensor.pm25_1.state | float > 20 or states.sensor.pm25_2.state | float > 20 %}
{% if is_state('binary_sensor.door_window_sensor_158d000248cb4b', 'on') %}
' high dust, though opened window. air purifier is not working.'
{% elif is_state('switch.sonoff1_airpurifier1', 'off') and is_state('switch.sonoff2_airpurifier2', 'off') %}
'Air purifier On'
{% endif %}
{% endif %}
{% if states.sensor.pm10_1.state | float < 10 and states.sensor.pm10_2.state | float < 10 and states.sensor.pm25_1.state | float < 10 and states.sensor.pm25_2.state | float < 10 and is_state('switch.sonoff1_airpurifier1', 'on') and is_state('switch.sonoff2_airpurifier2', 'on') %}
'Air purifier Off'
{% endif %}
- delay:
seconds: 3
- service_template: >
{% if (states.sensor.pm10_1.state | float > 20 or states.sensor.pm10_2.state | float > 20 or states.sensor.pm25_1.state | float > 20 or states.sensor.pm25_2.state | float > 20) and is_state('binary_sensor.door_window_sensor_158d000248cb4b', 'off') %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
entity_id:
- switch.sonoff1_airpurifier1
- switch.sonoff2_airpurifier2