Expose Entity State Zen Thermostat

I have a pair of Zen Thermostats, one is hardwired, the other runs on battery power only. I’m running into an issue where Home Assistant just shows the state as unknown for the power entity on the battery-powered device, and I can’t figure out how to expose an attribute under it.

image

I want to take the battery_voltage attribute and use that to give an estimated battery percentage left. I’ve started by trying to add a new entity as a sensor template.

template:
  - sensor:
      - name: "Upstairs Thermostat Battery Level"
        unit_of_measurement: "%"
        state: >
          {% set battery = states('sensor.upstairs_thermostat_power.battery_voltage') %}
          {{ ((battery)) }}

With the end goal being to take the new battery attribute and do some math to come up with the rough battery percentage as shown in this SmartThings handler (SmartThingsPublic/zen-thermostat.groovy at baedfcbfff71000ba1b56e6138d38c9a890204f5 · SmartThingsCommunity/SmartThingsPublic · GitHub)

The problem I’m running into is that at best I can get the new battery entity created, but it always shows as a state of unknown. Am I totally off-base with the idea of using the sensor template and can this be done at all? I’m migrating over from Hubitat and the device handler for it there also covered the battery level, so between that and the SmartThings handler, I know it’s possible to see that info, just not sure how to get at it here in Home Assistant. Any help is greatly appreciated, thanks!

Change the template to this:

{{ state_attr('sensor.upstairs_thermostat_power', 'battery_voltage') }}
1 Like

That did it, you rule! :slight_smile:

Can I use multiplication/division on this entity or do I need to do the same kind of deal as before with setting it as ‘battery’ and then doing it within that section?

Edit - figured it out actually (rough numbers), I ended up with the following if anyone follows along in the future. Many thanks to you @Burningstone!

template:
  - sensor:
      - name: "Upstairs Thermostat Battery Level"
        unit_of_measurement: "%"
        state: >
          {%set battery = state_attr('sensor.upstairs_thermostat_power', 'battery_voltage') %}
          {{ (battery - 3.4) * 38.46 | int }}
1 Like

Thanks for thinking about the future readers. Can I ask how you determined the 3.4 subtraction and the 38.46 multiplication?

My thinking was I could multiply the voltage of each battery (~1.5 volts) by the number of batteries (4) for and then use that value (about 6) as a denominator/factor… So something like this…

{% set battery = state_attr('sensor.zen_thermostat_power', 'battery_voltage') | float %}
{% set battery = battery / 6 * 100 %}

So for example, my battery_voltage attribute reads about 5.2 so this translates to about 87%

On another note, my battery voltage always seems to read 5.2. Not sure if the device is super efficient and I haven’t seen a drop yet or if the info is incorrect. I’m leaning towards the incorrect theory considering that the state of the power entity is UNKNOWN.
Have you seen correct values for the battery in your setup since you configured it?

Sorry for the delayed response, don’t spend enough time logged in here :slight_smile:

I was going off the SmartThings device handler from the OP, specifically line #429.

            def minVolts = 34  // voltage when device UI starts to die, ie. when battery fails
            def maxVolts = 60  // 4 batteries at 1.5V (6.0V)

It appears to line up with my experience as I’m sitting at 4.1 (26%) and have the low battery indicator on the thermostat as well. I’m slightly tempted to just let it run and wait to find out where the threshold is but I’ll likely swap it by 10%.

Fwiw, the state of the thermostat’s power entity also shows as Unknown for me, so that may not be an issue. I’d just expect you to end up seeing the battery fail around 56% or 57% based on the difference between the subtraction vs division numbers.

Thanks for the feedback. And sorry for my late reply. Not sure why I didn’t receive an email notification when you replied.

I hadn’t noticed the the min and max values in the device handler. So I ended up doing a similar formula in my setup like lines 429 - 431.
Except I am using 65 as the “max” battery because I just replaced the batteries in my thermostat yesterday and the battery_voltage attribute shows a value of 6.5 instead of 6.0. So I’m guessing this is supposed to be 65
I’ll see if this works out for me.

1 Like

Hi there, I have an unrelated question I was hoping you could shed some light on? I have a hvac that can’t have its thermostat changed - but I have full control of it (currently in Hubitat and Google home, moving to HA and HomeKit).

I’m looking for a physical thermostat with up and down arrows to place in the guest room to control heating and cooling without using an app.

You wouldn’t happen to know if this could support that? Basically can I get this to interact/sync with the “virtual” thermostat I’ve got in HA, without physically connecting it to the hvac?

I would think you might be able to hack that together with some automation rules, but it wouldn’t be an out of the box fit at least. You would likely have a better setup just going with some buttons or a scene controller/smart switch next to a little display if you need the current temp shown?