Automation, compare sensor with numeric helper

We live in a house where we still cook on (hopefully not Russian) gas. Unfortunately, the ventilation of the house is seriously deficient. For this I built a CO2 sensor, so that I at least get notifications when there is too much CO2 in the air, like with cooking.

However, I actually want to set up the automation so that I only get notifications when the CO2 level exceeds a certain value and keeps rising. And not if it drops (provided it is not severe).

For this, I have a condition in mind, but it doesn’t seem to work:

condition: numeric_state
entity_id: sensor.nocnoc_mhz19b_carbondioxide
above: "{{ states('input_number.co2_helper_a') }}"

I get the error message:

Message malformed: expected float for dictionary value @ data['condition'][0]['above']'

The value of the helper is delayed updating by another automation.
I’m doing something wrong, I know, but I don’t understand why it’s going wrong or how to fix it…
Would you guys mind taking a look with me?

You got that error message because the above option doesn’t support templating.

I suggest you use a Template Condition.

condition: template
value_template: "{{ states('sensor.nocnoc_mhz19b_carbondioxide') | float(0) > states('input_number.co2_helper_a') | float(0) }}"
1 Like

Thanks Taras,

That works amazingly good!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

It does support reading from numeric entities without a template, like this:

condition: numeric_state
entity_id: sensor.nocnoc_mhz19b_carbondioxide
above: input_number.co2_helper_a

See the fifth example here:


just had a very similar problem, your post just fixed it, thanks!

1 Like