markgdev / home-assistant_OctopusAgile

Octopus Agile custom component for Home Assistant
Apache License 2.0
86 stars 33 forks source link

sensor.octopus_agile_current_rate is a string not a number #91

Closed ppmt closed 2 years ago

ppmt commented 2 years ago

Describe the bug The sensor state is correctly displaying the rate but it is a string rather than a number.

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Develloper Tools/ Template'

  2. Enter the following code {% if states('sensor.octopus_agile_current_rate') is number %} It is a number {% else %} It is not a number {% endif %}

  3. Check what is written in the right panel

Expected behavior I expected the state of the sensor to be number (so that it can be used in the Energy integration as the electicity cost)

ppmt commented 2 years ago

It looks like I misunderstood how template works.

states(..) will return a string whatever the sensor is as per this page

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

and more precisely

states('device_tracker.paulus') will return the state string (not the object) of the given entity or unknown if it doesn’t exist.

So I think it was a non issue to start with. I will close it

markgdev commented 2 years ago

Well I learnt something new here, I didn’t know that was the case!