|
Post by gandalph on Jun 3, 2015 22:36:56 GMT
Hi, I've been trying to wrap my head around how to query the (computourist v2.2) Gateway from openhab. I have created an item:
Number itm_node1_up_mqtt "Uptime GW[%.1f min]" <clock> {mqtt="<[mymosquitto:home/rfm_gw/nb/node01/dev00:state:default]"} // node 01, device 0, upTime mins NORTHbound which gets updated nicely when I post this msg on the bus: mosquitto_pub -t home/rfm_gw/sb/node01/dev00 -m "upTime"
Only thing is: how do I get itm_node1_up_mqtt updated regularly (initiated from openhab)? For this to happen I figured I need to publish a msg to the bus from openhab like this:
Number itm_node1_up_query "Uptime GW[%.1f min]" <clock> {mqtt=">[mymosquitto:home/rfm_gw/sb/node01/dev00:state:default]"} // node 01, device 0, upTime mins SOUTHbound however the way to trigger this item eludes me... I have the following rule in place, but that has not the intended effect, I am sure it must be an easy fix, anyone?
/* --- GW uptime ---- */
rule "GW uptime update" when Time cron "0 0/1 * * * ?" //http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/tutorial-lesson-06 then //sendCommand(itm_node1_up_query) //not working... //postUpdate(itm_node1_up_query) //not working... Refresh(itm_node1_up_query //not working... end
thanks
|
|
|
Post by diverseg on Jun 4, 2015 14:30:59 GMT
This is how I have done it and have it working Note:substutite your mymosquitto everywhere i have mqttbroker
In my items file Group All Group Network (All) Group Nodes <nodes> (Network) // Uptime, BATT_Voltage, SW_Version, RSSI
String getNode1SwVer "get Node1 SwVer" {mqtt=">[mqttbroker:home/rfm_gw/sb/node01/dev03:command:*:default]"} String getNode2SwVer "get Node2 SwVer" {mqtt=">[mqttbroker:home/rfm_gw/sb/node02/dev03:command:*:default]"}
String Node1SwVer "Node1 SwVer [%s]" <firmware> (Nodes) {mqtt="<[mqttbroker:home/rfm_gw/nb/node01/dev03:state:default]"} String Node2SwVer "Node2 SwVer [%s]" <firmware> (Nodes) {mqtt="<[mqttbroker:home/rfm_gw/nb/node02/dev03:state:default]"}
String getNode1UpTime "get Node1 UpTime" {mqtt=">[mqttbroker:home/rfm_gw/sb/node01/dev00:command:*:default]"} String getNode2UpTime "get Node2 UpTime" {mqtt=">[mqttbroker:home/rfm_gw/sb/node02/dev00:command:*:default]"}
Number Node1UpTime "Node1 UpTime [%d Mins]" <uptime> (Nodes) {mqtt="<[mqttbroker:home/rfm_gw/nb/node01/dev00:state:default]"} Number Node2UpTime "Node2 UpTime [%d Mins]" <uptime> (Nodes) {mqtt="<[mqttbroker:home/rfm_gw/nb/node02/dev00:state:default]"}
String getNode2Rssi "get Node2 rssi" {mqtt=">[mqttbroker:home/rfm_gw/sb/node02/dev02:command:*:default]"} Number Node2Rssi "Node2 RSSI [%.1f db]" <network> (Nodes) {mqtt="<[mqttbroker:home/rfm_gw/nb/node02/dev02:state:default]"}
String getNode2Voltage "get Node2 Vdd" {mqtt=">[mqttbroker:home/rfm_gw/sb/node02/dev04:command:*:default]"} Number Node2Voltage "Node2 [%.3fVdd]" <battery> (Nodes) {mqtt="<[mqttbroker:home/rfm_gw/nb/node02/dev04:state:default]"}
In my rules file
// query every 5 min rule "refresh SwVer, UpTime, RSSI, Voltage" when Time cron "0 0/5 * * * ?" then sendCommand(getNode1SwVer, "READ") sendCommand(getNode2SwVer, "READ") sendCommand(getNode1UpTime, "READ") sendCommand(getNode2UpTime, "READ") sendCommand(getNode2Rssi, "READ") sendCommand(getNode2Voltage, "READ") end
in the sitemap i have an entry Group item=Nodes label="Nodes" icon="nodes"
Realize that the rule only runs every 5min so don't expect an update until then. Some people edit the node code to transmit these values without having to be requested but there really is no need, how often are these values changing really?
That should help ya
|
|
|
Post by gandalph on Jun 4, 2015 20:54:59 GMT
awesome! that worked, thanks
|
|
|
Post by computourist on Jun 5, 2015 8:47:01 GMT
You could do it with cron, like I described in another threat:
To update the RSSI value in Openhab on a regular interval:
- define an openhab item: (in xxx.items)
String getRSSI "get rssi" {mqtt=">[mosquitto:home/rfm_gw/sb/node03/dev02:command:*:default]"}
- make a rule, FE an automatic query every 5 minutes: (in xxx.rules)
rule "refresh RSSI" when Time cron "0 0/5 * * * ?" then sendCommand(getRSSI, "READ") end
|
|