Hi all,
I have “build” my own integration with my energy meter and are now getting the hourly data into Home assistant as a sensor which looks like this:
It is basically a python script in AppDaemon that runs every hour, to get the data for the hour before it.
The code for it looks like this:
def update(self, kwargs):
self.log('Enegic Energy update started')
token = self.get_token() # Token will be retrieved from cache or newly fetched
packets = self.get_usage(token)
for period in packets:
if period == 'PhaseHour':
self.log('Use the hour data')
deviceName = period
friendlyName = f'Enegic - {deviceName}'
self.log(friendlyName)
sensor = f'sensor.enegic_{deviceName.replace(" ","_").replace(".","_").lower()}_energy'
epochTime = (packets[period]['ts'] / 1000)
energyTime = datetime.fromtimestamp(epochTime, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
iavg = packets[period]['data']['iavg']
voltage = 230
wh_usage = [current * voltage for current in iavg]
# Total Wh usage
total_wh = sum(wh_usage)
self.log(f'{friendlyName} , {energyTime}, {total_wh}')
self.set_state(entity_id = sensor,
friendly_name = friendlyName,
device_class = 'energy',
state_class = 'measurement',
unit_of_measurement = 'Wh',
state = total_wh,
attributes = {
'last_updated_hour': energyTime
})
This all seems to work, but I cannot use the created sensor in my Energy Dashboard and I can’t find out how to do it.
I have already created a helper like this:
utility_meter:
enegic_hourly_energy:
source: sensor.enegic_phasehour_energy
cycle: hourly
However, this one shows strange data, and I can’t even select it in the energy dashboard:
Can someone assist me in how to get this to work properly ?
Thank you in advance!