Comparing temperature sensors to turn on/off fan

I an running Home Assistant 2021.12.9 on a linux hosted VM.

My objective, simplified, is to compare an aerq temperature and humidity sensor (aerq_temp) with an Ecobee sensor (eco_temp) and if the aerq_temp is above the eco_temp then the action would be to start the ceiling fan. The automation created below provided the expected results using the template editor but gives “false” results to all options when traced. I also have had problems getting the automation triggered with only platform: state so I added platform: time_pattern to try to isolate the issue(s). I would appreciate a review of the automation and suggestions.

alias: MBR Ceiling Fan
description: ''
trigger:
  - platform: state
    entity_id: sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3
    for:
      hours: 0
      minutes: 0
      seconds: 0
    to: 'null'
  - platform: time_pattern
    minutes: /5
    seconds: '*'
    hours: '*'
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              "{{
              states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3')
              | float > states('sensor.master_bedroom_temperature') | float }}"
        sequence:
          - service: fan.set_percentage
            target:
              device_id: a80f9d842ef5e10e5f0e04896d3f4721
            data:
              percentage: 30
      - conditions:
          - condition: template
            value_template: >-
              "{{
              states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3')
              | float <= states('sensor.master_bedroom_temperature') | float }}"
        sequence:
          - service: fan.set_percentage
            target:
              device_id: a80f9d842ef5e10e5f0e04896d3f4721
            data:
              percentage: 0
      - conditions:
          - condition: template
            value_template: >-
              "{{
              states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3')
              | float < 70.0 }}"
        sequence:
          - service: fan.set_percentage
            target:
              device_id: a80f9d842ef5e10e5f0e04896d3f4721
            data:
              percentage: 0
    default: []
mode: queued
max: 10

Your state trigger was only if the sensor went ‘null’. Below would trigger on any state change. The templates look okay. The templates don’t need quotes since you are using a multi-line character.

You mention that you get the expected results from the templates. If you could post the following in the template editor and paste the output:

{{ states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3') }}
{{ states('sensor.master_bedroom_temperature') }}
{{ states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3') | float > states('sensor.master_bedroom_temperature') | float }}
{{ states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3') | float <= states('sensor.master_bedroom_temperature') | float }}
{{ states('sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3') | float < 70.0 }}

Thank you for responding! I added the “Null” configuration just grasping for ideas. Also thanks for pointing out the my use of quotes…I am obviously still learning. Below is the output from the template editor:

image

I think they may have been aiming for null but used the string 'null' by mistake instead:


https://www.home-assistant.io/docs/automation/trigger/#state-trigger

The correct form would be:

trigger:
  - platform: state
    entity_id: sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3
    for:
      hours: 0
      minutes: 0
      seconds: 0
    to: 
  - platform ...etc
1 Like

When I read the docs my interpretation was that adding Null would trigger all state changes and that was okay since I did not call out any attributes. But I think now this was wrong scince the entity_id needs the attributes to make the comparison. Removing Null now makes the automation work but so far only on the time_pattern platform. I’ll watch it and see if the state platform triggers the automation. Thank you for your help!

To test without waiting, go to Developer tools / States, find sensor.aerq_temperature_and_humidity_sensor_v2_0_air_temperature_3 and adjust its state (this is not permanent, the next state update from the sensor will overwrite your change, or you can change it back manually).

Thank you for pointing that out. Yes, I did that and the automation works. The state changes on the sensors do not seem to happen on the polling period ,15 minutes, and I was looking for some other pattern. Both of them track ‘Last Changed’ in Lovelace and they can go well beyond 15 minutes without a change or then change in 3 minutes.

1 Like