Last active
June 20, 2016 09:27
-
-
Save nickbalch/08ede397467c1d02189203fd8bf9f216 to your computer and use it in GitHub Desktop.
Moteino items and rules for Openhab. An MQTT broker is used to send data from the nodes. Openhab subscribes to the broker and picks up the updates. Nodes are configured to send data every 15 minutes. For ease of configuration and transparency, I have chosed to use a rule to map the nodes 1-5 to specific items. Moteinos are very mobile, so if one…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Group Moteino (State) | |
Group Moteino_batt (Moteino,Battery) | |
Group Moteino_temp (Temperature) | |
Group Moteino_signal (Moteino) | |
Group Moteino_monitor (Moteino,Status) | |
Group Moteino_version | |
Switch moteino_0_monitor "Node 0 Monitor" (Moteino_monitor) | |
Switch moteino_1_monitor "Node 1 Monitor" (Moteino_monitor) | |
Switch moteino_2_monitor "Node 2 Monitor" (Moteino_monitor) | |
Switch moteino_3_monitor "Node 3 Monitor" (Moteino_monitor) | |
Switch moteino_4_monitor "Node 4 Monitor" (Moteino_monitor) | |
Switch moteino_5_monitor "Node 5 Monitor" (Moteino_monitor) | |
Number moteino_0_temp "Node 0 Temp [%.1f C]" (Moteino,Temperature,Moteino_temp) {mqtt="<[mosquitto:home/status/moteino_0_temp:state:default]"} | |
Number moteino_0_batt "Node 0 Batt [%.1f V]" (Moteino) {mqtt="<[mosquitto:home/status/moteino_0_battery:state:default]"} | |
Number moteino_0_signal "Node 0 Signal [%.1f Db]" (Moteino) {mqtt="<[mosquitto:home/status/moteino_0_signal:state:default]"} | |
Number moteino_0_version "Node 0 Version [%s]" (Moteino,Moteino_version) {mqtt="<[mosquitto:home/status/moteino_0_version:state:default]"} | |
Number moteino_1_temp "Node 1 Temp [%.1f C]" (Moteino,Temperature,Moteino_temp) {mqtt="<[mosquitto:home/status/moteino_1_temp:state:default]"} | |
Number moteino_1_signal "Node 1 Signal [%.1f Db]" (Moteino,Moteino_signal) {mqtt="<[mosquitto:home/status/moteino_1_signal:state:default]"} | |
Number moteino_1_batt "Node 1 Batt [%.1f V]" (Moteino,Moteino_batt) {mqtt="<[mosquitto:home/status/moteino_1_battery:state:default]"} | |
Number moteino_1_version "Node 1 Version [%s]" (Moteino,Moteino_version) {mqtt="<[mosquitto:home/status/moteino_1_version:state:default]"} | |
Number moteino_2_temp "Node 2 Temp [%.1f C]" (Moteino,Temperature,Moteino_temp) {mqtt="<[mosquitto:home/status/moteino_2_temp:state:default]"} | |
Number moteino_2_signal "Node 2 Signal [%.1f Db]" (Moteino,Moteino_signal) {mqtt="<[mosquitto:home/status/moteino_2_signal:state:default]"} | |
Number moteino_2_batt "Node 2 Batt [%.1f V]" (Moteino,Moteino_batt) {mqtt="<[mosquitto:home/status/moteino_2_battery:state:default]"} | |
Number moteino_2_version "Node 2 Version [%s]" (Moteino,Moteino_version) {mqtt="<[mosquitto:home/status/moteino_2_version:state:default]"} | |
Number moteino_3_temp "Node 3 Temp [%.1f C]" (Moteino,Temperature,Moteino_temp) {mqtt="<[mosquitto:home/status/moteino_3_temp:state:default]"} | |
Number moteino_3_signal "Node 3 Signal [%.1f Db]" (Moteino,Moteino_signal) {mqtt="<[mosquitto:home/status/moteino_3_signal:state:default]"} | |
Number moteino_3_batt "Node 3 Batt [%.1f V]" (Moteino,Moteino_batt) {mqtt="<[mosquitto:home/status/moteino_3_battery:state:default]"} | |
Number moteino_3_version "Node 3 Version [%s]" (Moteino,Moteino_version) {mqtt="<[mosquitto:home/status/moteino_3_version:state:default]"} | |
Number moteino_4_temp "Node 4 Temp [%.1f C]" (Moteino,Temperature,Moteino_temp) {mqtt="<[mosquitto:home/status/moteino_4_temp:state:default]"} | |
Number moteino_4_signal "Node 4 Signal [%.1f Db]" (Moteino,Moteino_signal) {mqtt="<[mosquitto:home/status/moteino_4_signal:state:default]"} | |
Number moteino_4_batt "Node 4 Batt [%.1f V]" (Moteino,Moteino_batt) {mqtt="<[mosquitto:home/status/moteino_4_battery:state:default]"} | |
Number moteino_4_version "Node 4 Version [%s]" (Moteino,Moteino_version) {mqtt="<[mosquitto:home/status/moteino_4_version:state:default]"} | |
Number moteino_5_temp "Node 5 Temp [%.1f C]" (Moteino,Temperature,Moteino_temp) {mqtt="<[mosquitto:home/status/moteino_5_temp:state:default]"} | |
Number moteino_5_signal "Node 5 Signal [%.1f Db]" (Moteino,Moteino_signal) {mqtt="<[mosquitto:home/status/moteino_5_signal:state:default]"} | |
Number moteino_5_batt "Node 5 Batt [%.1f V]" (Moteino,Moteino_batt) {mqtt="<[mosquitto:home/status/moteino_5_battery:state:default]"} | |
Number moteino_5_version "Node 5 Version [%s]" (Moteino,Moteino_version) {mqtt="<[mosquitto:home/status/moteino_5_version:state:default]"} | |
Number Moteino_Chart_Period "Chart Period" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openhab.core.library.types.* | |
import org.openhab.core.persistence.* | |
import org.openhab.model.script.actions.* | |
import org.joda.time.* | |
var String[] buffer | |
var String[] tmp | |
rule "Mapping Moteino nodes to temperature items" | |
when | |
Item Moteino_temp received update | |
then | |
Moteino_version.members.forEach[t | | |
tmp=t.name.toString.split("_") | |
// println(t.name+" which was updated at "+t.lastUpdate) | |
// println("Next line should be temp for Moteino_"+tmp.get(1)) | |
// println(Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
if (t.lastUpdate.after(new java.util.Date(now.minusMinutes(2).millis))) { | |
switch (tmp.get(1)) { | |
case tmp.get(1) == "0" : postUpdate(Temperature_GF_Understairs,Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
case tmp.get(1) == "1" : postUpdate(Temperature_xx_Unused,Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
case tmp.get(1) == "2" : postUpdate(Temperature_FF_Spare,Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
case tmp.get(1) == "3" : postUpdate(Temperature_GF_Dining,Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
case tmp.get(1) == "4" : postUpdate(Temperature_FF_Bed,Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
case tmp.get(1) == "5" : postUpdate(Temperature_FF_Roan,Moteino_temp.members.findFirst[name.contains(tmp.get(1))].state) | |
} | |
} | |
] | |
end | |
rule "Check Last updated for Nodes" | |
when | |
Time cron "0 0/30 * * * ?" | |
then | |
Moteino_version.members.forEach[i | | |
buffer=i.name.toString.split("_") | |
println(i.name+" "+i.state+" "+i.lastUpdate) | |
if (i.lastUpdate.before(new java.util.Date(now.minusMinutes(30).millis)) || i.state==Uninitialized){ | |
println(i.name+" not updated or not initialized") | |
if ( Moteino_monitor.members.findFirst[ name.contains(buffer.get(1))].state ==ON ) { | |
sendCommand(Alert_1,buffer.get(0)+" "+buffer.get(1)+" not updated for 30 minutes") | |
} | |
} | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment