MQTT trigger with numerical sensor value

Hi everybody,

i´m struggling to get an automation going:

  • a CO2 sensor (via MQTT) ist up and running so that i can see the CO2 level in HA - works fine:
? "sensor 3"
: 
  name: CO2
  platform: mqtt
  state_topic: office/sensor2
  unit_of_measurement: ppm
  value_template: "{{ value_json.co2 }}"
  • a switch ist installed and running to switch on/off manually the ventilation - works fine:
? "switch 3"
: 
  - 
    command_topic: office/switch3/set
    name: "Ventilation Switch"
    optimistic: false
    payload_off: "OFF"
    payload_on: "ON"
    platform: mqtt
    qos: 0
    state_topic: "office/switch3/#"
  • the numeric value / state should trigger a ventilation switch to start running above 600 ppm level:
automation: 
  - 
    alias: "Ventilation"
    trigger: 
      - 
        platform: numeric_state
        entity_id: sensor.co2
        above: 600
        value_template: "{{ value_json.co2 }}"
    action:
      -
        platform: mqtt
        topic: office/switch3/set
        payload_on: "ON"  

I´m a newbie and struggling quite a bit to get it going, help very appreciated!

Kind regards!

joe

Problem solved, the automation attached below is running nicely in combination with a binary_switch as “tool”:

binary_sensor: 
  - 
    platform: template
    sensors: 
      co2alarm: 
        friendly_name: CO2 Alarm
        value_template: > 
           {{ states('sensor.co2') | float > 700 }}
        entity_id: sensor.co2
automation: 
  - alias: Fan on!
    trigger: 
       entity_id: binary_sensor.co2alarm
       platform: state
       state: 'on'
    action:
       service: mqtt.publish
       data:
           topic: 'office/switch3/set'
           payload: 'ON'
  - alias: Fan off! 
    trigger: 
       entity_id: binary_sensor.co2alarm
       platform: state
       state: 'off'
    action:
       service: mqtt.publish
       data:
           topic: 'office/switch3/set'
           payload: 'OFF'
  - alias: Fan should be on!
    trigger:
        platform: mqtt
        topic: 'office/switch3/set'
        payload: 'OFF'
    action:
       service: mqtt.publish
       data:
           topic: 'office/switch3/set'
           payload: 'ON'
    condition:
        condition: template
        value_template: >
           {{ states('sensor.co2') | float > 700 }}