Fix missing updates of AQI for CO2 sensor

The switch status_light is supposed to toggle whether the LED
reflects the current air quality,
but turning it off also disabled updates to the AQI text sensor,
leading to outdated values in HomeAssistant.

Now the text sensor is always updated
and the switch only controls the LED.
This commit is contained in:
Philipp Wendler
2026-06-28 11:47:26 +02:00
committed by GitHub
parent 43939c1816
commit 6d2f2be8df
+37 -20
View File
@@ -143,11 +143,13 @@ sensor:
name: "CO2"
id: "co2"
on_value:
if:
condition:
switch.is_on: status_light
then:
- script.execute: update_aqi
- script.execute:
id: update_aqi
- if:
condition:
switch.is_on: status_light
then:
- script.execute: update_light
temperature:
name: "Temperature"
id: "temperature"
@@ -326,14 +328,37 @@ script:
then:
- if:
condition:
or:
- sensor.in_range:
id: co2
above: 1500
sensor.in_range:
id: co2
above: 1500
then:
- text_sensor.template.publish:
id: aqi
state: Bad
else:
- if:
condition:
sensor.in_range:
id: co2
above: 800
below: 1500
then:
- text_sensor.template.publish:
id: aqi
state: Acceptable
else:
- text_sensor.template.publish:
id: aqi
state: Good
- id: update_light
mode: restart
then:
- if:
condition:
text_sensor.state:
id: aqi
state: Bad
then:
- light.turn_on:
id: led
brightness: 100%
@@ -343,15 +368,10 @@ script:
else:
- if:
condition:
or:
- sensor.in_range:
id: co2
above: 800
below: 1500
text_sensor.state:
id: aqi
state: Acceptable
then:
- text_sensor.template.publish:
id: aqi
state: Acceptable
- light.turn_on:
id: led
brightness: 50%
@@ -359,9 +379,6 @@ script:
green: 100%
blue: 0%
else:
- text_sensor.template.publish:
id: aqi
state: Good
- light.turn_on:
id: led
brightness: 50%