Sensor attribute value divided by 24

Hello.
I am trying to create an uptime sensor showing the number of days a server has been online.
I have an attribute of an entity which gives me the number of hours the server has been online, I just need this in days.

Below is what I have but just get unavailable on the created sensor.
I have other sensors that are using similar math so have no idea why this one just won’t play ball.

    - name: ESXi Days Uptime
      unit_of_measurement: days
      state: >
        {{ ((sensor.esxi_vmhost_1.attributes.uptime_hours|int) /24)|round(1) }}

Any assistance would be hugely appreciated. Thanks.

No need for the |int filter. The attribute is already a number. Only states are strings that need conversion to a number type before doing mathematical operations.

Also the correct way to access the attribute is:

states.sensor.esxi_vmhost_1.attributes.uptime_hours However…
^^^^^^^^^^

https://www.home-assistant.io/docs/configuration/templating/#states

So putting that all together:

    - name: ESXi Days Uptime
      unit_of_measurement: days
      state: >
        {{ (state_attr('sensor.esxi_vmhost_1', 'uptime_hours') /24)|round(1) }}
2 Likes

Legend. That worked a treat. Thanks so much, spent hours on this… -_-