I want to combine several CO2 Sensors

Hi,

I have several CO2 Sensors and have config a view with nice graphes.

Now I want to combine these sensors for the main view to show only an alert if one is over a limit. So I like to show a status ‘CO2 is OK’, or if one goes over a limit ‘CO2 alert at Bedroom’. Any idea how to start with this?

Thanks, Steffen

I know this could be done with a for loop in a template sensor, but I’m absolutely terrible with those so I’ll provide an alternative.

Create a template binary sensor for each CO2 sensor using

{{ float(states('sensor.sensor_name')) > threshold }}

as the value_template. Replace sensor_name with the entity ID of the sensor, and replace threshold with whatever value is unsafe. Also set device_class to safety in the template sensor. These sensors will display Unsafe if the level is above the threshold, and Safe if it’s below the threshold.

Then use an entity filter card in your frontend to only display those template sensors with a state of on (Unsafe).

You could use a template sensor instead of a binary template sensor if you wanted the output to say “CO2 alert at [location]” like you wanted, but it’s simpler to set up a template binary sensor (and it might still fit your needs).

Thank you, but I like to have only one line at the frontend to have a status:

CO2 OK

or

CO2 Bedroom alert (maybe red)

or

CO2 Bedroom, Kitchen alert (maybe red)

Somethink like this. So I think I have to look at template sensor …

Steffen

To clarify, I meant you could set up a template sensor for each CO2 monitor to individually display “CO2 alert at [location].” You’d still end up with several sensors instead of one with a for loop in a single template sensor.

Although, how many CO2 monitors do you have? Because you could do exactly what you want to accomplish with a single template sensor without a for loop, but it would just be more complicated. If you had three sensors, you could do something like this as the value_template in a single template sensor (this example assumes sensor1 is Bedroom, sensor2 is Kitchen, and sensor3 is Guest Room):

{% set threshold = 100 %}
{% if float(states('sensor.sensor1')) > threshold and float(states('sensor.sensor2')) > threshold and float(states('sensor.sensor3')) > threshold %}
  CO2 Bedroom, Kitchen, Guest Room alert
{% elif float(states('sensor.sensor1')) > threshold and float(states('sensor.sensor2')) > threshold %}
  CO2 Bedroom, Kitchen alert
{% elif float(states('sensor.sensor1')) > threshold and float(states('sensor.sensor3')) > threshold %}
  CO2 Bedroom, Guest Room alert
{% elif float(states('sensor.sensor2')) > threshold and float(states('sensor.sensor3')) > threshold %}
  CO2 Kitchen, Guest Room alert
{% elif float(states('sensor.sensor1')) > threshold %}
  CO2 Bedroom alert
{% elif float(states('sensor.sensor2')) > threshold %}
  CO2 Kitchen alert
{% elif float(states('sensor.sensor3')) > threshold %}
  CO2 Guest Room alert
{% else %}
  CO2 OK
{% endif %}

Change the sensor names and outputs as necessary, and set the threshold to whatever you want. You can see this is ridiculously complicated but it would indeed accomplish what you’re looking for. It becomes even more complicated if you have more than three sensors, but the concept is the same.

This is why I wish I could understand for loops…I’ve been trying.

If you use the built-in Developer Tools \ Automation Editor, the example that comes up on the default screen has a good, working example of a for loop iterating through a collection.

I’ve seen that example many times and I still struggle lol

Hang in there, and keep trying. Sometimes, it takes a while before it clicks, and just works for you. ;^)

Hi,

I have working on that an getting this:

{% set threshold = 1000 %}
{% set output = namespace(text="CO² Warnung") %}
{% for entity in states.group.grp_co2.attributes.entity_id if float(states(entity)) > threshold %}
  {{- entity}}
  {% if float(states(entity)) > threshold %}
    {{- states(entity)}}
    {% set output.text = (output.text ~ entity.friendly_name) %}
  {% endif %}
{% else %}
  {% set output.text = "CO² OK" %}
{% endfor %}
{{output.text}}

The only thing not working is ‘{% set output.text = (output.text ~ entity.friendly_name) %}’ here the entity object do not know the friendly_name or name. I want to get a list of the sensors are over the treshhold.

Thanks, Steffen

Now I get a workaround for the attributes:

      {% set threshold = 1000 %}
      {% set output = namespace(text="CO² Warnung") %}
      {% for entity in states.group.grp_co2.attributes.entity_id if float(states(entity)) > threshold %}
        {% if float(states(entity)) > threshold %}
          {% set parts = entity.split('_') -%}
          {% set output.text = output.text ~ "\n" ~ (parts[1] | capitalize) ~ " " ~ states(entity) %}
        {% endif %}
      {% else %}
        {% set output.text = "CO² OK" %}
      {% endfor %}
      {{output.text}}

But how you can see I have a line feed to have every room at a line. But the entity card shows the output in one line.

Any posibilities to show one sensor with a multiline value?

Regards Steffen

I want to do the same. It is becoming a problem during winter. Which sensors you have?

I have Netamo sensors.