Hi Friends!
I’ve find lot of similar topic but no one help me solve this issue.
I’ve an air quality sensor based on ESP. It can measure different values. My goal is set a category from 1-6 for each measured values. The ranges of measured values are not the same and this is why i do not want use automations for all possible outputs. My idea was a template sensor but it does not appear in my entity list, here is my code.
template:
- trigger:
- trigger: state
entity_id: sensor.aiq1_h1_pm1
sensor:
- name: "aiq1 pm1 cat"
state: >
{% set a1pm1 = states('sensor.aiq1_h1_pm1') | float %}
{% if a1pm1 >= 0 and a1pm1 < 6.7 %}
{% set aiq1h1pm1 = 1 %}
{% elif a1pm1 >= 6.7 and a1pm1 < 26.2 %}
{% set aiq1h1pm1 = 2 %}
{% elif a1pm1 >= 26.2 and a1pm1 < 41.2 %}
{% set aiq1h1pm1 = 3 %}
{% elif a1pm1 >= 41.2 and a1pm1 < 93.7 %}
{% set aiq1h1pm1 = 4 %}
{% elif a1pm1 >= 93.7 and a1pm1 < 168.7 %}
{% set aiq1h1pm1 = 5 %}
{% elif a1pm1 >= 168.7 %}
{% set aiq1h1pm1 = 6 %}
{% else %}
{{ a1pm1 }}
{% endif %}
- name: "aiq1 pm25 cat"
state: >
{% set a1pm25 = states('sensor.aiq1_h1_pm2_5') | float %}
{% if a1pm25 >= 0 and a1pm25 < 9 %}
{% set aiq1h1pm25 = 1 %}
{% elif a1pm25 >= 9 and a1pm25 < 35.4 %}
{% set aiq1h1pm25 = 2 %}
{% elif a1pm25 >= 35.4 and a1pm25 < 55.4 %}
{% set aiq1h1pm25 = 3 %}
{% elif a1pm25 >= 55.4 and a1pm25 < 125.4 %}
{% set aiq1h1pm25 = 4 %}
{% elif a1pm25 >= 125.4 and a1pm25 < 225.4 %}
{% set aiq1h1pm25 = 5 %}
{% elif a1pm25 >= 225.4 %}
{% set aiq1h1pm25 = 6 %}
{% else %}
{{ a1pm25 }}
{% endif %}
I will be happy for any idea.
I’ve programmed the ESP to measure in every 5 minutes for 30 sec and swich of the sensor, this is why i try to use the trigger-> state template.
When it will work i have to check all air quality sensor and choose the biggest value (1-6, the biggest is the worst) and this will be the quality of the air.