Is home not a number?

I have successfully used the trigger and condition “Axel is away”. I now wanted to generalize it and tried if home is below 0.5. In case it needed to be interger I also tried below 1. Neither worked. Is home not a numeric value that can be queried? Danke and please be patient with an utter newbie.

If you have device tracking set, up, the state of zone.home should be a number representing the number of trackers in the zone (so it should never be 0.5). As with all entity states, it’s stored as a string.

Please paste the YAML code for the automation that is not behaving how you expect, and explain what it is doing.

Here’s an example automation from my system that turns the heating on if the house is occupied and I am not working from home on my own.

  trigger:
    - platform: state
      entity_id: zone.home
      from: '0'
    - platform: state
      entity_id: binary_sensor.wfh_solo
      to: 'off'

  condition:
    - condition: numeric_state
      entity_id: zone.home
      above: 0
    - condition: state
      entity_id: binary_sensor.wfh_solo
      state: 'off'

  action:
    - service: climate.set_preset_mode
      entity_id: climate.central_heating
      data:
        preset_mode: 'comfort'
1 Like

Thank you. That’s it. So it is a state and a string. That’s not what the documentation says. There I’m told it’s the number of current occupants so I treated it as a numeric value:
trigger:

  • platform: numeric_state
    entity_id: zone.home
    value_template: “”
    below: 1
    condition:
    action:

Sorry about the formatting. Copy/paste behaves strangely here.

Just surround the code with
``` above and below it.

One more question: Why is your state a string as trigger and a number as condition? Are you sure both work as intended? The numeric trigger doesn’t, I tried that out. You are right, persons is integer. But comparisons are tricky with integers. Is it strictly greater and less or is it greater or equal and less or equal? With floats you can just ignore the exactly equal case, it doesn’t really matter what it’s counted as. But with integers you can’t. So using 0.5 is unambiguous, the true number is either well above or well below.

The GUI editor typically saves it is a string.

The trigger in this case is a state check, not a numeric_state check. Because states are strings, then Home Assistant is likely converting anything here to a string before comparing it anyway. 99% of the time, people are looking for text, not numbers.

for the condition though every state in Home Assistant is being stored internally as a string, so it’s probably getting automatically converted to a float behind the scenes, so that stuff like using an input_number helper instead of a hardcoded value will work.

Why am I saying float instead of integer? Because I, like many people in the community, have automations that deal with temperatures - and I’m almost never working with a whole number.

For example I have automations that deal with it getting below zero outside, but rather than below 0, I use below 0.1

I have automations that deal with solar, for example - above 1.6 for 10 minutes.

  • States are always strings.
  • The Numeric state trigger / condition automatically converts the string to a number (if possible).
  • The allowable syntax for the State trigger means that I could have omitted the quotes but I chose not to.
  • Yes, my automation works fine thank you.

I think the actual issue with your Numeric state trigger is that you have set a value_template with an invalid value. Delete that line and re-save the automation.

I use each of the following triggers in a few automations and trigger-based template sensors, and they work fine.

trigger:
  - platform: numeric_state
    entity_id: zone.home
    below: 1

and

trigger:
  - platform: numeric_state
    entity_id: zone.home
    above: 0

As you see above, that’s exactly what I used and it definitely did not work. Writing the trigger with a string does, so I’m fine with that now. The problem with trying things out is that it takes many minutes for zone.home to react to turning WLAN off and on in my phone. I don’t know where my empty value_template line came from, the visual editor wrote that. Wish that just trying stuff out was easier here.

It isn’t exactly what you used if you had that value_template set. What that does is:

  • Read in the state of zone.home
  • Throw it away and use the empty string instead
  • Compare the empty string with the threshold value

In other words, it won’t work at all.

This is why the “how to help us help you” guidelines include items 9 and 11: if you’d pasted your automation, correctly formatted, in post 1, we would have picked up that error much sooner.

Thank you. I have tried things out now and your combination, trigger on string, check condition as number, works as intended. So I’ll stick with that for the time being. Why the visual editor adds that line that breaks everything is beyond me. I had probably clicked that field and left it again without entering anything. I stick with checking for above or below 0.5 for the reason given above. It works.