asantaga / lightwaverf_HA_EnergySensor

Home Assistant Sensor for the LightwaveRF energy monitor
MIT License
5 stars 3 forks source link

Energy metrics not being collected #10

Open proffalken opened 2 years ago

proffalken commented 2 years ago

Hello,

Since #7 was fixed I've gone back through my config and confirmed that I can talk to my WiFiLink (LW390) from the Raspberry Pi that is running HA.

If I send the command !R1D1F1 to the Link on UDP 9760 then the appropriate light turns on, so that's fine.

I'm still not seeing any data from the energy monitor however, and the log is full of lines such as:

2021-08-19 07:40:26 ERROR (SyncWorker_10) [custom_components.lightwaverf_energy.sensor] No data received from lightwaveRF energy monitor timed out

https://api.lightwaverf.com/energy.html#communication suggests that the energy meter data should be sent as a UDP broadcast (which is exactly what the code is expecting), however even if I run Netcat listening for broadcast data, I still can't see any data from the Link at all.

I'm now wondering if the LWLink has stopped broadcasting as even a tcpdump -n 'broadcast' isn't showing the packets from the Link - can anyone else confirm this behaviour?

gshoebridge commented 2 years ago

I'm seeing data intermittently but not enough to be confident of the total I notice other attributes available - could these be used toward the total daily usage?

asantaga commented 2 years ago

Hey,

I too have noticed this on my server, but then all of a sudden it started working again. Is you HA Server on the same network as the LFRF WifiLink? I remember when developing that if I was connected to a different AP I also didnt get the packets..

this piece of code can be run on anything to test its receiving data..

import json
import logging
import socket
import time
data = None
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('0.0.0.0', 9761))
sock.settimeout(30.0)  # Wait a Max of 30 seconds

while True:
    try:
       print("Waiting for data from LWRF Energy Device")
       data, _ = sock.recvfrom(1024)  # buffer size is 1024 bytes
       print("Data received from LWRF Energy %s " % data)
    except socket.timeout as ex:
       print("No data received  ")

oh and firewalls, thats the otherthing I tweaked on my server.. let me know if this works

gshoebridge commented 2 years ago

Will have a go - I run a Mac mini and would use terminal

Using varying network options - will look to bring lw off wifi

asantaga commented 2 years ago

I have the LW930, i have it hardwired, actually I dont think it has WIFI support..

it should work on a macmini too, i originally developed the code on a macbook pro but it now runs on my ubuntu server..

let me lknow

gshoebridge commented 2 years ago

Will do and thanks Agreed hub is wired only - use a wifi link to a mini hub for most automation hubs (in office) so might be causing issues


From: Angelo Santagata @.> Sent: Saturday, August 21, 2021 11:38:50 AM To: asantaga/lightwaverf_HA_EnergySensor @.> Cc: gshoebridge @.>; Comment @.> Subject: Re: [asantaga/lightwaverf_HA_EnergySensor] Energy metrics not being collected (#10)

I have the LW930, i have it hardwired, actually I dont think it has WIFI support..

it should work on a macmini too, i originally developed the code on a macbook pro but it now runs on my ubuntu server..

let me lknow

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fasantaga%2Flightwaverf_HA_EnergySensor%2Fissues%2F10%23issuecomment-903097141&data=04%7C01%7C%7C618163bd885348ad669f08d9648fdd47%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637651391314105740%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=tYTAHivpDDz3UHcf%2F5%2Fzswl16oJNvPSS8JXl7Z%2BqCls%3D&reserved=0, or unsubscribehttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAISWBJQLN7UIHNW7RBBXBU3T5563VANCNFSM5CNRN6ZA&data=04%7C01%7C%7C618163bd885348ad669f08d9648fdd47%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637651391314115736%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2BRjsmg3g6WnU%2BpvylrtnluW96Rd3FtKQ4SW1r2U68bs%3D&reserved=0.

gshoebridge commented 2 years ago

what should i run to get import json.... etc working?

gshoebridge commented 2 years ago

data recovered

Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43826,"mac":"03:3D:5D","time":1629565152,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":446,"todUse":14608}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43827,"mac":"03:3D:5D","time":1629565167,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":450,"todUse":14610}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43828,"mac":"03:3D:5D","time":1629565182,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":448,"todUse":14612}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43829,"mac":"03:3D:5D","time":1629565197,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":448,"todUse":14613}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43830,"mac":"03:3D:5D","time":1629565212,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":443,"todUse":14615}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43831,"mac":"03:3D:5D","time":1629565227,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":437,"todUse":14617}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43832,"mac":"03:3D:5D","time":1629565242,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":439,"todUse":14619}' Waiting for data from LWRF Energy Device Data received from LWRF Energy b'!{"trans":43833,"mac":"03:3D:5D","time":1629565257,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":437,"todUse":14621}' Waiting for data from LWRF Energy Device ^[Data received from LWRF Energy b'*!{"trans":43834,"mac":"03:3D:5D","time":1629565272,"pkt":"868R","fn":"meterData","prod":"pwrMtr","serial":"5253FE","type":"energy","cUse":437,"todUse":14623}' Waiting for data from LWRF Energy Device

asantaga commented 2 years ago

Sorry, looks like I cut'n'pasted something without checking , the code doesnt use json or even time, sorry, but I think you figured it out.

Well the data is coming through.. From the macMini? or the HA Server..

proffalken commented 2 years ago

I too have noticed this on my server, but then all of a sudden it started working again. Is you HA Server on the same network as the LFRF WifiLink? I remember when developing that if I was connected to a different AP I also didnt get the packets..

Yup, LW930 (no LCD display) hardwired to the same VLAN as the Pi that's running HomeAssistant, and as I say sending commands to the LWLink results in the correct lights activating, I'm just not seeing anything from the energy monitor.

The energy monitor is definitely working though, because I can see the data in the LWRF app.

proffalken commented 2 years ago

Fwiw, I rebooted the lwlink and it all started working again...

gshoebridge commented 2 years ago

data collected on Mac mini - data being seen intermittently in HA server

Looks like 15 second polling.

asantaga commented 2 years ago

Hey, in sensor.py (line56) the timeout is set to 10seconds. I did that as the code isnt async and I didnt want to hang the HA thread. Can you try changing it to say 20 and see how that works. Im not 100% sure if HA will like that and I probably need to port the code to an async model..