I am trying to set the automation to turn on/off according to the sensor of dust.
I have 2 dust sensors and the each sensor can detect the pm2.5 and pm10.
I wanna put the automation like below
-
The one of the 4 figure from 4 dust sensor will be more than 30, the 2 air purifier will be turned on
-
The all 4 figure will be less than 5, the 2 air purifier will be turn off.
And the script I made is like below. But it does not work. Is there anyone who can provide me the information?
- alias: Dust_airpurifier_ONOFF
initial_state: True
trigger:
- platform: template
value_template: "{% if states.sensor.pm10_1.state | float > 30 or states.sensor.pm10_2.state | float > 30 or states.sensor.pm25_1.state | float > 30 or states.sensor.pm25_2.state | float > 30 %} 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_template: >
{% if states.sensor.pm10_1.state | float > 30 or states.sensor.pm10_2.state | float > 30 or states.sensor.pm25_1.state | float > 30 or states.sensor.pm25_2.state | float > 30 %}
switch.turn_on
{% elif 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 %}
switch.turn_off
{% endif %}
entity_id: switch.sonoff1_airpurifier1
entity_id: switch.sonoff2_airpurifier2