LightWaveRF as a data source to EmonCMS

Hi I'm new to the forum but I have been using emon for a while - I have also been looking (and purchased) some more LiightWaveRF devices. Beyond the works done with MQTT to switch lightwave devices on and off has anyone looked at / interested in pulling data from devices (radiator valves / thermostats) into Emon?

I have done some research looking at requesting / listening for data (easiest is UDP) - responses are JSON and I figured (because I'm not a software developer!) it should be reasonably easy to pick the data from the lightwave link (via UDP) and strip the JSON for teh values needed and then post to emon as a feed???

My ultimate aim is to get to the real time OpenBEM running using these feeds + using the intelligence from the feeds to proactively control the heating.

I can post my current findings / info .. i'm hitting a wall due to my lack of programming skills :-)

 

 

 

 

 

borpin123's picture

Re: LightWaveRF as a data source to EmonCMS

There is a Lightwaverf node in node-red https://www.npmjs.com/package/lightwaverf so you can probably create a flow into emoncms via MQTT.  Note some other posts if you want to use JSON. I'm doing just this with an Edimax smartplug.

Sorry this is just a nodejs module.

j0hngi11am's picture

Re: LightWaveRF as a data source to EmonCMS

thanks for the link I will check that out, I made some progress last night with some very basic python. I can make a request of the lightwavelink (LWL) for a specific device and wait for the response and pull out the value. 

I'm just looking at how to take the value from the JSON string and reform them to do a url post to the emonCMS 
 
e.g. the full JSON string would be (below is the 'print' result from json.loads)

{u'prod': u'tmr1ch', u'ver': 33, u'output': 100, u'prof': 5, u'cTarg': 22.0, u'nTarg': 18.5, u'state': u'run', u'cTemp': 19.3, u'mac': u'20:37:1D', u'batt': 3.22, u'time': 1452849394, u'router': u'20371D', u'serial': u'F46C02', u'trans': 806, u'type': u'temp', u'nSlot': u'10:00'}

I want to pull out the keys cTarg cTemp batt time 

then reform them to a http://172.16.44.149/input/post.json?time=1452849394&node=1&json={cTarg:22, cTemp:19.3, batt:3.22}@apikey=xxxxxxx

is this easy to do?? I have been googling around and I can't find a straight forward help on 

how to extract just a few keys needed, then contrstuct the url... 

this is the basic script to listen:

import socket
import json

UDP_IP_LISTEN = "172.16.44.149"
UDP_PORT_LISTEN = 9761

sock = socket.socket(socket.AF_INET, # Internet
                      socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP_LISTEN, UDP_PORT_LISTEN))

counter = 0
while True:
     data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
     if data[0][0] != "*":
       print "!"
     else:
       json_string = data[2:]
       if 'prod' in (data):
    parsed_json = json.loads(json_string)
    print parsed_json #prints the full JSON
    print parsed_json['cTemp'] #prints just the value for key cTemp

​and this is the script to make the requests:

import socket
import json
import time

#list of devices
device = "R2Dh"
#this is the code you received when pairing this device

LWL_PAIR_CODE = "666"
RANDOM = "123"
BANG = "!"
LWL_REQ = "F*r"

#Send
UDP_IP_SEND = "172.16.44.148"
UDP_PORT_SEND = 9760
MESSAGE = LWL_PAIR_CODE + "," + RANDOM + "," + BANG + device + LWL_REQ
print "UDP target IP:", UDP_IP_SEND
print "UDP target port:", UDP_PORT_SEND
print "message:", MESSAGE

sock = socket.socket(socket.AF_INET, # Internet
                      socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP_SEND, UDP_PORT_SEND))

n = 15
sum = 0
counter = 1
while counter <= n:

    sum = sum + counter
    counter += 1
    print "message:", MESSAGE
    print "counter:", counter

    sock = socket.socket(socket.AF_INET, # Internet
                      socket.SOCK_DGRAM) # UDP
    sock.sendto(MESSAGE, (UDP_IP_SEND, UDP_PORT_SEND))

    print "sleeping..."
    time.sleep(5)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.