I had a quick look around at this too and didn’t manage to find much. I also couldn’t work out why it was being represented as a string. I checked the code and there is no obvious reason, just before it is returned, it’s a number. If you work out what is needed let me know.
At this point I think we need the help of some of the Energy dev.
So your integration is returning a number for that sensor? it is strange indeed that it shows up as a string in the dev tools/template.
Have you got unit_of_measurement: GBP/kWh attribute?
yes it is. I triple check the spelling several time
Just before it sets the value it does a round so about as much of a number as python gets I think?
current_rate = round(current_rate, 2)
self._state = current_rate
I did Phil… do you need any more information?
I haven’t heard anything back from you…
Strange indeed but you confirm that once out of your code it is no longer a number but a string?
Or is just for me that it is the case?
Yes, using your template it also shows as being a string, very odd
This might actually not be a problem since it still doesn’t work once the str is converted to a float.
I am not sure how to get more help on this issue. Can you actually write a “bug” on the Energy tab? if so where?
I was having a play with this tonight, my power sensors aren’t setup properly yet, but I notice if I set the price manually it’s in EUR/kWh, could this be part of the issue?
I don’t know if this will help or not. I’m on Go Faster, so just have an automation which changes the price twice a day, but it might give some hints:
Also check in the server general configuration, you currency is set to GBP:
So with your sensor it does work @badguy and you see the cost in the Energy tab in the Sources section?
@Markg I do see GBP/kWh if I select fixed price. As badguy says you need to go and change it in the setting of HomeAssistant.
Would it be possible to pull the gas consumption into a sensor which could be fed into the energy tab.
I know it is 24hours behind but would be good enough for me.
Yes, it is working for me - I think the entity needed to be in pounds / kWh rather than pence / kWh, which makes the resolution not as good as it could be, but it seems ok.
Here is my sensor
I have just setup my own sensor which reference @Markg component sensor (sensor.octopus_agile_current_rate) and converts it to GBP/kWh from p/kWh (I think) and should work no matter what octopus tariff you are on
If i am correct I think the dashboard is expecting GBP/kWh but Mark’s component produce p/kWh
Currently on Octopus GO with the override of the agile price enabled and I am on 0.05p & 0.1533p per kWh with octopus
The sensor.octopus_agile_current_rate returns 15.33 p/kWh
My sensor returns 0.1533 GBP/kWh which I think is what the Energy dashboard is expecting
Again, I think it’s in the right format so will see after my reboot and HA Energy dashboard does its first calculation
- platform: template
sensors:
octopus_price:
friendly_name: "Octopus Current Price GBP/kWh"
value_template: "{{ states('sensor.octopus_agile_current_rate') | float /100 }}"
unit_of_measurement: GBP/kWh
Here is mine so not much different than yours!
- sensor:
- name: "Agile_actual_rate"
unit_of_measurement: "GBP/kWh"
state: >
{{ (states.sensor.octopus_agile_current_rate.state|float) / 100 }}
I actually closed my issue on github. I misunderstood how states(sensor) works. It will return a string irrelevant of the real status of the sensor.
The correct way to test for a float is:
{% if float(‘name_sensor’) %}
it will return true or false…
Sorry for the confusion. But it still doesn’t explain why the sensor is not working in the energy tab
Any luck with your sensor?
Nope. Did yours work?