Flash lights every time the measured CO2 value is above a 1000 ppm

Hi guys,

need some support from you.

In my home I have several NETATMO sensors which also measures the CO2 concentration. In addition I have several HUE lights. All are integration in Home Assistant already.

I now want to automate it in the way that everytime the Netatmo sensor measures a value above 1000 ppm the light in that room flashes once.

My sensor has the entity id sensor.netatmo_home_schlafzimmer_eltern_co2 and delivers new data every 10 minutes.

I have the following automation configured:

What I see now is that the lights flash exactly once (at the time netatmo delivers new data), after the automation was saved.

Does anybody has an idea how I can change the behaviour so that it flashes every 10 seconds as long as the value us above 1000 (resp. 500 in my current test-setup)?

Thanks!

Could you post the YAML, by eyes are not as good as they were 20 years ago.

https://www.home-assistant.io/blog/2020/07/22/release-113/

Repeat until.

Hi Glenn,

I had to put everything in one screenshot, because new members are allowed to post only one image.

Here is the YAML file:

alias: Flash Lights in BĂĽro if CO2 is too high
description: A new measurement is done every 10 minutes
trigger:
  - platform: numeric_state
    entity_id: sensor.netatmo_home_schlafzimmer_eltern_co2
    above: '500'
condition: []
action:
  - type: flash
    device_id: 77d0cdc711025d5cdaa0f70200b730e8
    entity_id: light.buro_hue
    domain: light
  - service: notify.mobile_app_iphone_11_pro_grimm
    data:
      message: C02 zu hoch im BĂĽro
mode: restart
max: 10

The numeric state trigger only triggers when the value goes from below the threshold to above the threshold and then it only triggers again when the value goes below the threshold and then above the threshold again.
To flash it every time when the value is above 500, try something like this:

trigger:
  - platform: state
    entity_id: sensor.netatmo_home_schlafzimmer_eltern_co2
condition: 
  - condition: template
    value_template: "{{ trigger.to_state.state > 500 }}"

Another option is to use repeat while:

action:
  - repeat:
      while:
      - condition: numeric_state
        entity_id: sensor.netatmo_home_schlafzimmer_eltern_co2
        above: '500'
      sequence:
      - type: flash
        device_id: 77d0cdc711025d5cdaa0f70200b730e8
        entity_id: light.buro_hue
        domain: light
      - wait_template: '00:00:10'
1 Like

Thanks for your help.

Should the trigger look like this

trigger:
  - platform: template
    value_template: '{{ sensor.netatmo_home_schlafzimmer_eltern_co2 > 500 }}'

or

trigger:
  - platform: template
    value_template: '{{ states('sensor.netatmo_home_schlafzimmer_eltern_co2') | float > 500 }}'

I found the second one somewhere else, but it did not work correctly neither.

Will try with the first one now.

This trigger will not work, it’ll do the same as the numeric state trigger. It will only trigger when it changes from false to true and then only again whrn it goes to false and then to true again.

I just reread your initial post and I see that you want it to flash every 10 seconds, but this means once it goes above 500, it will flash every 10 seconds for at least 10 minutes because you only get a new reading every 10 minutes. So at minimum it will flash 60 times. Do you really want to do this??

I don’t want to flash it every 10 seconds, but only once with each new value (every 10 minutes).

Please ignore my post with the “new” triggers above. I have not read your proposal carefully.

I’ll try with your code now:

trigger:
  - platform: state
    entity_id: sensor.netatmo_home_schlafzimmer_eltern_co2
condition: 
  - condition: template
    value_template: "{{ trigger.to_state.state > 500 }}"

Then use the code I posted. It will trigger every time the sensor changes value (every 10 mins) and it will only flash the light when the value is above 500.

I’ve updated my yaml file with your code and it now looks like this:

alias: Flash Lights in BĂĽro if CO2 is too high
description: A new measurement is done every 10 minutes
trigger:
  - platform: state
    entity_id: sensor.netatmo_home_schlafzimmer_eltern_co2
condition:
  - condition: template
    value_template: '{{ trigger.to_state.state > 500 }}'
action:
  - service: notify.mobile_app_iphone_xxx
    data:
      message: C02 too high
  - type: flash
    device_id: 77d0cdc711025d5cdaa0f70200b730e8
    entity_id: light.buro_hue
    domain: light
mode: single

Unfortunately it’s never triggered although the CO2 value is above 500.

Any ideas?

Try changing the condition to this:

'{{ trigger.to_state.state | float > 500 }}'

I must have missed something… why can’t @stid just use a numeric_state condition of above 500? Why use a template?

Numerix state condition would also work, but not a numeric state trigger. I just like compact code, that’s why I showed the template condition.

Hey @Burningstone

Thanks again for your input. With the last changes it works like a charm.

This is my final yaml file:

alias: Flash Lights if CO2 is too high in BĂĽro during day
description: A new measurement is done every 10 minutes
trigger:
  - platform: state
    entity_id: sensor.netatmo_home_schlafzimmer_eltern_co2
condition:
  - condition: template
    value_template: '{{ trigger.to_state.state | float > 1000 }}'
  - condition: time
    after: '08:00:00'
    before: '23:00:00'
action:
  - type: flash
    device_id: 77d0cdc711025d5cdaa0f70200b730e8
    entity_id: light.buro_hue
    domain: light
mode: single
max: 10

Additionally I added another condition which restrict the flashing to day-time.

Honestly I don’t understand the concept of templates yet. I have to read the documentation somewhen. But I’m very happy that it works now!

2 Likes