Temperature sensor not reliable

I have two automations that turn on my basement fan when my thermostat detects the temperature is over 70, and turns it off when it goes under. I have minimal conditions, namely that it only turns on when the outdoor temp is >68 and it only turns it off when the outdoor temp is <70

For some reason, it’s not working consistently - and I can’t figure out how to troubleshoot it.

Here are the two YAMLs:

alias: Turn On basement fan when > 70
description: Turns on the outlet when the indoor temperature is 70°F or more
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.family_room_temperature
    above: 69.8
condition:
  - condition: numeric_state
    entity_id: weather.forecast_home
    attribute: temperature
    above: 68
action:
  - type: turn_on
    device_id: 9ca8e4a11be4876c42256d99bb9b6157
    entity_id: 7489520a46e4c4f785d034b020f03a37
    domain: switch
mode: single

alias: Turn off Basement Fan when < 70
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - climate.family_room
    attribute: current_temperature
    below: 69.8
  - platform: numeric_state
    entity_id:
      - sensor.family_room_temperature
    below: 69.8
condition:
  - condition: numeric_state
    entity_id: weather.forecast_home
    attribute: temperature
    below: 70
  - condition: device
    type: is_on
    device_id: 9ca8e4a11be4876c42256d99bb9b6157
    entity_id: 7489520a46e4c4f785d034b020f03a37
    domain: switch
action:
  - type: turn_off
    device_id: 9ca8e4a11be4876c42256d99bb9b6157
    entity_id: 7489520a46e4c4f785d034b020f03a37
    domain: switch
mode: single

Multiple times now I’ve checked my dashboard and the temperatures SHOULD have triggered this, but for some reason haven’t - and times like this morning that Traces say it triggered, yet the fan is not on - and the dashboard doesn’t see it on - so it SHOULD have re-triggered (I’ve validated their state = 0 so they’re not stuck)
The thing that really confuses me is that it HAS worked properly, so i feel like it should either always work or always not work.

So my question is two fold: How can I troubleshoot this, and does anyone see something obvious I’m missing.

With troubleshooting, my hope was to somehow trace what happens each time my temps update and find out why it isn’t triggering - but that’s my other frustration, i can’t figure out how to even see the refresh period of my Nest integration.

Note: I really SHOULD get some z-wave or other actual temp sensors rather than relying on cloud systems - my goal for 2024 is to get as much off of the cloud as possible, but I’ve sadly invested a lot into ‘cloud’ technology so either have to possibly flash things to local only, or possibly setup some sort of API interceptor that I can use to fake out systems into thinking they’re talking to the cloud (Or, buy new everything which the CFO might not approve of, lovely wife though she may be)

Every - and I mean every, condition needs a trigger. You have conditions that are not reflected in the triggers.

So if the triggers you have happen while the weather condition says no, and subsequently the weather changes, you do not have a trigger to check that now that condition is met, and the action should now happen.

For instance the first automation, chances are the room is hotter then outside. If the room is already hot, the outside temperature rises too, but there is no trigger that sees that happen.

To say it differently: If two conditions need to happen simultaneously, either condition changing could lead to them both being true. That is why both need a trigger.

1 Like

supporting @Edwin_D , here’s a really good page on how it works:

1 Like

Can you elaborate a little bit on what you mean by ever condition needs a trigger? I thought conditions were just used as 'make sure these other things are “state” / “true/False” else don’t run

That was super helpful, too.

You guys are great, thank you.

I hadn’t realized that it is something that has to trigger only when over, and not a constant check.

Digging in, is it correct that I can use a template with a float to accomplish this?

`alias: Turn On basement fan when > 70
description: Turns on the outlet when the indoor temperature is 70°F or more
trigger:
  - platform: template
    value_template: >
      {{ states('sensor.family_room_temperature') | float > 69.8 }}
condition:
  - condition: state
    entity_id: switch.basement_fan_socket_1
    state: 'off'
action:
  - type: turn_on
    device_id: 9ca8e4a11be4876c42256d99bb9b6157
    entity_id: switch.7489520a46e4c4f785d034b020f03a37
    domain: switch
mode: single
`

I also added a state check to ensure it doesn’t try to run if the switch is already on, as that would be silly.

My concern is with whether what Edwin_D said, as if I need a trigger for the additional condition I added, it will only make it worse.

Edit: Honestly the outdoor temp isn’t critical, so I removed that; more, I think that in the summer there are plenty of times it’s hot as sin outside and I want that fan running, since the basement is cool (it is a vornado that pulls air up the stairs like a boss)

Edit 3: i messed the code up, edit to fix the entity_id

this looks much better.

yes, you can use a template like that. you could also have used the number_state/above. either’s fine.
if you really want to be above 70 (or really 70 and above, you can do >= 70.

holler at us if it doesn’t do what you want, but it looks pretty straightforward now.

one other thing… i’d recommend you not use device_id’s.

here’s why and how:

Ugh, yeah entity_ID is what everyone says to use but it’s sort of ‘default’ when you go to set things up… I feel like that’s going to take a complete redesign of HA to stop making that ‘default’ for people

Also i minorly messed up, i actually need it to trigger when it senses ANY change, and then evaluate that change with the template:

alias: Turn On basement fan when > 70
description: Turns on the outlet when the indoor temperature is 70°F or more
trigger:
  - platform: state
    entity_id: sensor.family_room_temperature
condition:
  - condition: template
    value_template: >
      {{ states('sensor.family_room_temperature') | float > 69.8 }}
  - condition: state
    entity_id: switch.basement_fan_socket_1
    state: "off"
action:
  - service: switch.turn_on
    entity_id: switch.basement_fan_socket_1
mode: single

I removed the device_id too =)

Edit: Now I just need to buy a temp sensor for the basement so that it doesn’t bother turning it on if that temp is >= to the upstairs temp. Not likely to happen but why take the risk!

are you sure you needed to make that change?

trigger:
  - platform: template
    value_template: >
      {{ states('sensor.family_room_temperature') | float >= 70.0 }}

this trigger should work fine. home assistant recognizes that you are selecting the sensor and it will check for this every time the state of that sensor changes. so you should not need to do what you did at the end. in fact, personally i prefer it that way.

also, i’d change to the >= above…

Using a template trigger is similar to a normal trigger. It also won’t “always” fire. What does that even mean? That the automation should perform the action every millisecond? Suppose you put a notification in the action, you do not want an endless stream of those.

As jou just realised from Automations #1: trigger only fires when it changes from not true to true - #4 by Stiltjack, a trigger is something happening, something becoming true. A condition is something being true. It is an “extra” check, as you said, but adding extra checks adds extra things you need to think about.

EDIT: That is why I added the below explanation to the wiki topic above. If you read that, you’ve read the below already:

If A and B need to be true for something to happen, then there are two ways that trigger (pun intended) both A and B both being true. If A becomes true, and B is already true, or if B becomes true and A is already true.

The general format for multiple conditions is:

trigger:
  A becomes true
  B becomes true
  C becomes true
  ...
condition:
  A is true
  B is true
  C is true
  ...
action:
  do something

I know this feels like double work, but remember only one trigger can fire at the same time, so you always need to check the other things too. With one condition, you only need one trigger, because it proves the only condition is already met.

A template trigger can help, because the template only becomes true ‘when all the stars align’ so to say. a template trigger {{ A and B and C }} will only become true once all is as it should be. So using (only) that you do not need a condition. But still, this does not “always” fire.

Always triggering would make it impossible to intervene. So event based, how it is now, is actually better suited for everything that is not absolutely critical to get right 100% of the time. For instance, an automation to turn the light off when there is no motion should not always fire, because you want to be able to turn the light on manually too. Motion sensors aren’t perfect. And especially in a home, you often cannot, or do not want to, write an automation that takes every situation into account. A home is not like a factory.

A time trigger often seems like an alternative to the “always fire” thought. But in fact, it is a worse way. If you check too often, HA is busy doing nothing all the time. Write 200 of those automations, and it is becoming messy soon. If you check infrequently, the automation is very slow to respond. Checking every 5 minutes implies you may need to wait almost 5 minutes for something to happen.

Using triggers as suggested works instantaneously, only in the situation intended, and leaves room for other automations (or people) to act on the same thing too.

2 Likes