Lightwaverf + Domoticz + graphing energy monitor

  • September 11, 2014 at 20:08 #15226

    Thought i’d just make a quick post.

    Create a virtual device in domoticz choose “Electric”

    Save the script as (edit the url string below with device idx displayed within domoticz and the IP/hostname of yout domoticz server to send the updates)

    Run the script:

    nohup python &

    Works a charm

    import socket
    import time
    import urllib2
    import re

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.SOL_UDP)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.sendto("001,@?", 0, ('' , 9760))

    sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock2.bind(('', 9761))

    while True:
    data, addr = sock2.recvfrom(1024) # buffer size is 1024 bytes
    print "received message:", data
    m ="(\d+)\,(\d+)\,(\d+),(\d+)",data)
    sock.sendto("001,@?", 0, ('' , 9760))

    You must be logged in to view attached files.
    September 11, 2014 at 20:19 #15228

    Sorry but the indentation has been removed.

    Link to code here:

    October 15, 2014 at 18:14 #16459

    Where exactly in Domoticz are you creating this virtual device?

    The only way I can see to add a device manually is via the ‘Switches’ tab -> ‘Manual Light\Switch’, but there is no ‘Electric’ option in there…

    October 15, 2014 at 18:44 #16460

    Do this much easier in my system 🙂

    developer of BMS Link ( A cloud based Home Automation platform for LightwaveRF, Z-Wave, RFXCOM.

    October 15, 2014 at 19:14 #16461

    Never mind. You have to create a Dummy hardware, then once that is in the list, there is a button called ‘Create Virtual Sensors’. This can then be configured as an ‘Energy’ type.

    Got it all working now. Had to hack the script though. There is no need to poll for the value anymore. The wifi link broadcasts a UDP message every 15 secs with a JSON string containing the latest values.

    October 27, 2014 at 09:50 #16635

    One important thing that I found out during this process is that:

    The ‘kWh So Far Today’ figure reported by the wifi link (and hence the app) is quite consistently about 20% less than what it should be. This seems to be a bug with the calculation of this figure.

    I calculated the figure myself in my script, and this was accurate to within about 2.5% of the actual reading. So this shows that the sensor is actually quite accurate, but the software which adds it up is not.

    November 1, 2014 at 05:28 #16726

    Here’s an updated script which doesn’t poll any more and just listens for the broadcast. Hope it is useful to someone:

    November 5, 2014 at 09:50 #16773
    dave kelly

    Thanks rhamnett.

    I hadn’t realized the energy protocol had changed in the most recent firmware update, so your script was very useful.

    I changed it a bit in my application though to read the string into a dictionary instead of a regular expression, then you can get the values by name

    November 7, 2014 at 11:30 #16799

    Inspired by rhamnett I have tweaked his script. The main problem I found is that Domoticz expects the ‘total’ figure to be the total for all time, rather than the daily total. If you pass the daily total in, then you will find that the total for the current day in the ‘Weekly’ graph is often incorrect (at least on the latest version of Domoticz).

    Also, and more importantly, I found that the daily total produced by the wifi link is quite innaccurate, being over 20% under in my case. I have changed the script therefore to calculate the total figure itself. After a week,the total figure is now very close to my actual reading via the meter.

    The new script also copes with Domoticz not running, or any loss of network communication.

    Create a User Variable in Domoticz called ‘lastEnergyUpdate’ of type ‘Float’ and set it to 0
    Install python if necessary using ‘sudo apt-get install python’

    Amend the following in the script:
    ip = your ip address and port for domoticz
    deviceIdx = the idx of your energy monitor in domoticz, which can be found on the Devices page
    userVarIdx = the idx of your user variable, which should match the position of the variable in the User Variables page e.g. if it is 2nd in the list, the value is 2

    Copy the script to /home/pi on the RPi
    Run with ‘python ./ &

    Add the following to /etc/rc.local to get the script to run on startup of the RPi.

    /usr/bin/python /home/pi/ &

    December 4, 2014 at 00:54 #17267

    Anyone noticed this has broken again as of 20th Nov?

    December 4, 2014 at 09:32 #17268

    All working ok here. What has broken exactly and what firmware version (Wifi Link) are you on?

    December 8, 2014 at 18:10 #17358

    Domoticz box had stopped receiving the broadcasts, anyway I rebooted the wifi link (it took two goes?!) and all is well again. Thanks for the reply.

    October 16, 2018 at 13:26 #25426

    I don’t use Linux much even though I’ve got Domoticz running on a RPi. generally speaking once I’ve got stuff working I tend not to go back to it so it’s been over 2 years since I set up my RPi with all my lightwave devices. I’ve recently gone back to it and set up the weather forecasting and am now looking to utilise the energy monitor. I’ve pretty much binned my Lightwave link box as I’m using an RFXCom 433x device that has a much better range.

    I’ve three questions about the above. first is that when running the script from @belissimo the pi returned the string
    [1] 31440
    that I’ve no idea about it’s meaning.

    2nd is that the script surely needs to be run at startup and I’ve long forgotten how to do that. It seems to change with every new version of Linux 🙂

    3rd how is the signal monitor itself actually identified and passed to Domoticz?

    Many thanks



    October 18, 2018 at 21:58 #25432

    You’ll probably be better off just picking up an Owl monitor which will work with the RFXcom. They are pretty cheap from flea bay.

    Running RFXCom with Domoticz on raspberry pi3. LWRF dimmer switches, PIRs and plug sockets. Some Homeeasy switches, harmony hub controlling AV and air con. Geofencing with Pilot app. Tado for heating and cooling.

    November 2, 2018 at 20:07 #25448

    Inspired by the hard work from rhamnett and bellissimo, I have further tweaked this script. I felt that although this original thread is quite old, it is still valid and working today and so I wanted to put something back to the forum.

    I have now added the ability to upload to Domoticz;
    – Temperature readings of LightwaveRF radiator valves (TRV’s)
    – Battery levels of the LightwaveRF TRV’s
    – Firmware level of the TRV’s
    – Firmware level of the LightwaveRF Link module
    I have therefore edited bellissimo’s original instructions below to cater for this;

    Create a User Variable in Domoticz called ‘lastEnergyUpdate’ of type ‘Float’ and set it to 0
    (Install python if necessary using ‘sudo apt-get install python’)

    Amend the following in the script (marked by XX):
    ip = your ip address and port for domoticz
    userVarIdx = the idx reference number of your user variable lastEnergyUpdate
    deviceIdx = the idx reference number of your energy monitor in domoticz, which can be found on the Devices page
    temp1FEIdx = TRV1 Temperature Idx reference number
    temp2REIdx = TRV2 Temperature Idx reference number
    temp3KIIdx = TRV3 Temperature Idx reference number
    battery1FEIdx = TRV1 Battery level Idx reference number
    battery2REIdx = TRV2 Battery level Idx reference number
    battery3KIIdx = TRV3 Battery level Idx reference number
    lwrfbaseIdx = LWRF Link Firmware Idx reference number (I used a “Text” dummy sensor in Domoticz)
    lwrftrvIdx = TRV Firmware Idx reference number (I used a “Text” dummy sensor)
    trv1 = “XXXXX” = TRV1 Serial Number – found from the Lightwave Manager web portal (hover mouse over the device) –
    trv2 = “XXXXX” = TRV2 Serial Number – found from the Lightwave Manager web portal (hover mouse over the device) –
    trv3 = “XXXXX” = TRV3 Serial Number – found from the Lightwave Manager web portal (hover mouse over the device) –

    Copy the script to /home/pi on the RPi
    Run with ‘python ./ &

    Download link for updated script below;

    Optional & important notes

    As written, the script ignores the additional features I have added. To enable them, remove the double ## at the start of each line for the respective new sections to read up to 3 TRV’s and the LightwaveRF link firmware. If you have more than 3 TRV’s, just copy and paste each section further down the script and update / add the additional variables for the serial numbers/Temperatures/Battery levels.

    The LightwaveRF link firmware can take up to an hour to update.
    The TRV data will only update when their measured data, e.g. temperature, changes.
    Also, the firmware version’s are only sent to Domoticz when the script first receives data from LightwaveRF or if the firmware is updated whilst Domoticz is running.

    Add the following to /etc/rc.local to get the script to run on start-up of the RPi.

    /usr/bin/python /home/pi/ &

    Hope this helps someone 🙂

You must be logged in to reply to this topic.