Closed Bart-1992 closed 2 years ago
For now, if people want to add the sensors to the Home Assistant Energy dashboard, add the following code to your configuration.yaml:
homeassistant:
customize_glob:
sensor.toon_p1_power_*_cnt_*:
device_class: energy
state_class: measurement
last_reset: "1970-01-01T00:00:00+00:00"
@cyberjunky Hi Ron,
A month ago i created my first custom component for A Solar platform. I am using your component for my rooted Toon and have started my journey by leaning from your code (hope that is okay), which i would like to thank you for.
As i am following the project i saw this issue being created, maybe we can help each other as i got a similar request today. I already reached out to Frenck if he could point me in to the right direction or to the documentation.
PS: I am also Dutch which might help within communication
I find the new energy dashboard nice, but it's much to complicated, why not just let user select all devices without the Class en and Device state bloatware
I understand what you are saying. Think this is so they can easily filter the possible entities and make it easy for unexperienced users .
I have started added support for it and copied this along it the smartmeter fork sensor.py as well. It currently only gives back device_class so i am missing something/doing it wrong.
Some snips of my adjustments:
SENSOR_TYPES = {
'gasused': ['Gas Used Last Hour', 'm3', 'mdi:fire', '', ''],
'gasusedcnt': ['Gas Used Cnt', 'm3', 'mdi:fire', '', ''],
'elecusageflowpulse': ['Power Use', 'Watt', 'mdi:flash', '', ''],
'elecusageflowlow': ['P1 Power Use Low', 'Watt', 'mdi:flash', '', ''],
'elecusageflowhigh': ['P1 Power Use High', 'Watt', 'mdi:flash', '', ''],
'elecprodflowlow': ['P1 Power Prod Low', 'Watt', 'mdi:flash', '', ''],
'elecprodflowhigh': ['P1 Power Prod High', 'Watt', 'mdi:flash', '', ''],
'elecusagecntpulse': ['Power Use Cnt', 'kWh', 'mdi:flash', 'energy', 'measurement'],
'elecusagecntlow': ['P1 Power Use Cnt Low', 'kWh', 'mdi:flash', 'energy', 'measurement'],
'elecusagecnthigh': ['P1 Power Use Cnt High', 'kWh', 'mdi:flash', 'energy', 'measurement'],
'elecprodcntlow': ['P1 Power Prod Cnt Low', 'kWh', 'mdi:flash', '', ''],
'elecprodcnthigh': ['P1 Power Prod Cnt High', 'kWh', 'mdi:flash', 'energy', 'measurement'],
'elecsolar': ['P1 Power Solar', 'Watt', 'mdi:weather-sunny', '', ''],
'elecsolarcnt': ['P1 Power Solar Cnt', 'kWh', 'mdi:weather-sunny', 'energy', 'measurement'],
'heat': ['P1 Heat', '', 'mdi:fire', '', ''],
}
for resource in config[CONF_RESOURCES]:
sensor_type = resource.lower()
name = SENSOR_PREFIX + SENSOR_TYPES[resource][0]
unit = SENSOR_TYPES[resource][1]
icon = SENSOR_TYPES[resource][2]
device_class = SENSOR_TYPES[resource][3]
state_class = SENSOR_TYPES[resource][4]
last_reset = "1970-01-01T00:00:00+00:00"
entities.append(ToonSmartMeterSensor(data, name, sensor_type, unit, icon, device_class ,state_class ,last_reset))
@property
def device_class(self):
"""Return the device class of measurement of this entity, if any."""
return self._device_class
@property
def state_class(self):
"""Return the state class of measurement of this entity, if any."""
return self._state_class
@property
def last_reset(self):
"""Return the last reset of measurement of this entity, if any."""
return self._last_reset
Nice approach! Will have a look later, bit busy with other things...
No problem, Will let you know if i have any updates myself
@djansen1987 Did some findling.
For the measurement value to be catched your need to change the Sensor object:
from homeassistant.components.sensor import SensorEntity
class ToonSmartMeterSensor(SensorEntity):
And you need to return last_reset:
self._last_reset = dt.utc_from_timestamp(0)
I also implemented SensorEntityDescription but the code is not ready to be released. Thinking about a rewrite to use more modern code (tuples, datacoordinator) But maybe you can whip up something to get us going? ;-)
@djansen1987 I released 1.0.15, can you have a look if it works?
@cyberjunky thanks for the update! Unfortunately it throws an error;
` Logger: homeassistant.config Source: config.py:445 First occurred: 20:00:16 (1 occurrences) Last logged: 20:00:16
Invalid config for [sensor.toon_smartmeter]: value must be one of ['elecprodcnthigh', 'elecprodcntlow', 'elecprodflowhigh', 'elecprodflowlow', 'elecsolar', 'elecsolarcnt', 'elecusagecnthigh', 'elecusagecntlow', 'elecusageflowhigh', 'elecusageflowlow', 'elecusageflowpulse', 'gasused', 'gasusedcnt', 'heat'] @ data['resources'][3]. Got 'elecusagecntpulse'. (See /config/sensors.yaml, line 126). Please check the docs at https://github.com/cyberjunky/home-assistant-toon_smartmeter `
Arg, will fix, hold on.
Created 1.0.16, wait or do refresh on HACS -> toon-smartmeter -> Update informatie
Confirmed working!!
Thanks a lot 😁
The code is experimental, no idea if values are right, we know in a few hours...
Hey guys, just installed the latest version, but it's crashing my Home Assistant, sort of.
Here is my log:
File "/home/homeassistant/.homeassistant/custom_components/toon_smartmeter/sensor.py", line 66, in <module> SENSOR_TYPES: Final[tuple[SensorEntityDescription]] = ( TypeError: 'type' object is not subscriptable
This comes after a whole lot of more errors. Removing the latest version and going back to 1.0.14 fixes it. Can somebudy help me with this or shall I open a new issue?
@cyberjunky My update works as wel, thanks. Also managed to implement it in my SAJ eSolar module learning from yours. Thanks!
Maybe a off topic question, but maybe you can help me out with this. I like to add my component to the HACS store but i get lost in the documentation. My GitHub repository should be set up correctly but don't know what to do next
Hey guys, just installed the latest version, but it's crashing my Home Assistant, sort of. Here is my log:
File "/home/homeassistant/.homeassistant/custom_components/toon_smartmeter/sensor.py", line 66, in <module> SENSOR_TYPES: Final[tuple[SensorEntityDescription]] = ( TypeError: 'type' object is not subscriptable
This comes after a whole lot of more errors. Removing the latest version and going back to 1.0.14 fixes it. Can somebudy help me with this or shall I open a new issue?
@Fietspomp86 can you post your config for toon-smart_meter pls, so I can have a look.
@cyberjunky My update works as wel, thanks. Also managed to implement it in my SAJ eSolar module learning from yours. Thanks!
Maybe a off topic question, but maybe you can help me out with this. I like to add my component to the HACS store but i get lost in the documentation. My GitHub repository should be set up correctly but don't know what to do next
I think you only have to create the hacs.json file and if you set "render_readme": false, also info.md
Thanks for the tip! Will have a look, already created the hacs.json and info.md. Think i needed to do a PR on the https://github.com/hacs/default/blob/master/integration file and add my repository there. It looks like it has made a pull request which need to be checked. (I am kind of new when it comes to collaborating on GitHub)
Hey guys, just installed the latest version, but it's crashing my Home Assistant, sort of. Here is my log:
File "/home/homeassistant/.homeassistant/custom_components/toon_smartmeter/sensor.py", line 66, in <module> SENSOR_TYPES: Final[tuple[SensorEntityDescription]] = ( TypeError: 'type' object is not subscriptable
This comes after a whole lot of more errors. Removing the latest version and going back to 1.0.14 fixes it. Can somebudy help me with this or shall I open a new issue?@Fietspomp86 can you post your config for toon-smart_meter pls, so I can have a look.
Yes sure, here is my config from configuration.yaml:
Pulse is disabled since I'm using a smart P1 meter.
I see another issue is mentioned here, from HomeWizard as well. My Python version is 3.8.10, running my Home Assistant in a venv on a NUC with Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-80-generic x86_64)
Just for having everything in here, here is the copy of system info:
version | core-2021.8.3 |
---|---|
installation_type | Home Assistant Core |
dev | false |
hassio | false |
docker | false |
user | homeassistant |
virtualenv | true |
python_version | 3.8.10 |
os_name | Linux |
os_version | 5.4.0-80-generic |
arch | x86_64 |
timezone | Europe/Amsterdam |
I have the same problem with this integration. I can reproduce it when I start Home Assistant with python 3.8.6
. When I start Home Assistant with python 3.9
, all seems to work fine.
I have the same problem with this integration. I can reproduce it when I start Home Assistant with python
3.8.6
. When I start Home Assistant with python3.9
, all seems to work fine.
Ok, just installed Python 3.9.6 on my NUC and now it's working indeed. Also, the PR works well with 3.8.
Anyway, I guess I'll stick to 3.9 now anyway. Hope this helps someone though!
Fixed 'type' object is not subscriptable issue and added some more improvements in version 1.0.17, thanks all!
Would be nice if the entities from this custom-integration could be used as entities within the new HA 2021.8 Energy management intergration and dashboard: https://www.home-assistant.io/docs/energy/