Lightwaverf + Domoticz + graphing energy monitor

LightwaveRF Communi… > Forum > LightwaveRF Hackers > Lightwaverf + Domot…

LightwaveRF Community: Welcome Forums LightwaveRF Hackers Lightwaverf + Domoticz + graphing energy monitor

This topic contains 14 replies, has 7 voices, and was last updated by  dgilbert2 1 week, 6 days ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #15226
     rhamnett says:

    rhamnett
    Participant

    Thought i’d just make a quick post.

    Create a virtual device in domoticz choose “Electric”

    Save the script as energymon.py (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 energymon.py &

    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, ('255.255.255.255' , 9760))

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

    while True:
    data, addr = sock2.recvfrom(1024) # buffer size is 1024 bytes
    print "received message:", data
    if re.search("1\\,\\?W=.*",data):
    m = re.search(r"(\d+)\,(\d+)\,(\d+),(\d+)",data)
    sock.sendto("001,@?", 0, ('255.255.255.255' , 9760))
    time.sleep(30)
    urllib2.urlopen("http://192.168.0.101:8080/json.htm?type=command&param=udevice&idx=46&nvalue=0&svalue="+m.group(1)+";"+m.group(3))

    Attachments:
    You must be logged in to view attached files.
    #15228
     rhamnett says:

    rhamnett
    Participant

    Sorry but the indentation has been removed.

    Link to code here: http://pastebin.com/4ZxUjtYe

    #16459
     bellissimo says:

    bellissimo
    Participant

    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…

    #16460
     skiv71 says:

    skiv71
    Participant

    Do this much easier in my system :)

    developer of BMS Link (http://linode.bmslink.co.uk). A cloud based Home Automation platform for LightwaveRF, Z-Wave, RFXCOM.
    #16461
     bellissimo says:

    bellissimo
    Participant

    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.

    #16635
     bellissimo says:

    bellissimo
    Participant

    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.

    #16726
     rhamnett says:

    rhamnett
    Participant

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

    http://pastebin.com/70qaAMag

    #16773
     dave kelly says:

    dave kelly
    Participant

    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

    #16799
     bellissimo says:

    bellissimo
    Participant

    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.

    Instructions
    ============
    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 ./energymon.py &

    energymon.py

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

    /usr/bin/python /home/pi/energymon.py &

    #17267
     rhamnett says:

    rhamnett
    Participant

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

    #17268
     bellissimo says:

    bellissimo
    Participant

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

    #17358
     rhamnett says:

    rhamnett
    Participant

    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.

    #25426
     Robpl says:

    Robpl
    Participant

    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

    rob

    Rob
    #25432
     markk says:

    markk
    Participant

    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.
    #25448
     dgilbert2 says:

    dgilbert2
    Participant

    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;

    Instructions
    ============
    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) – https://manager.lightwaverf.com/
    trv2 = “XXXXX” = TRV2 Serial Number – found from the Lightwave Manager web portal (hover mouse over the device) – https://manager.lightwaverf.com/
    trv3 = “XXXXX” = TRV3 Serial Number – found from the Lightwave Manager web portal (hover mouse over the device) – https://manager.lightwaverf.com/

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

    Download link for updated script energymon.py below;

    https://pastebin.com/g3XkiEUh

    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/energymon.py &

    Hope this helps someone :-)

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.