StefanH
(Stefan Haupt)
February 20, 2019, 11:47am
1
Hi all,
I’ve searched the forums for about 30min without success but I cannot believe there is no solution for this challenge. I’d like to strip down my code and achieve something like this:
if (value == 1) dummyitem = Item1
if (value == 2) dummyitem = Item2
dummyitem.dosomething()
How do I need to declare my dummyitem in a rule and how do I point it to Item1 or Item2?
Stefan
rossko57
(Rossko57)
February 20, 2019, 12:03pm
2
Techniques to “get hold” of Items in here
Please see Design Pattern: What is a Design Pattern and How Do I Use Them for how to read and use DPs.
Problem Statement
Often one will have a number of separate Items which are all related to each other in some way. For example, one might have a Contact on a door and a DateTime to represent when the last time the door was opened. This is easy enough to keep track of if there are only one or two such Items, but if one has a lot of similar Items or is using a lot of generically coded rules where…
1 Like
StefanH
(Stefan Haupt)
February 20, 2019, 12:28pm
3
awesome. For anyone else interested in this topic. Here is the code I used:
rule "get shelly announce data"
when
Item ShellyAnnounce received update
then
var String sID = transform("JSONPATH", "$.id", ShellyAnnounce.state.toString)
var String sIP = transform("JSONPATH", "$.ip", ShellyAnnounce.state.toString)
var String sFWVerFull = transform("JSONPATH", "$.fw_ver", ShellyAnnounce.state.toString)
var String sFWVer = sFWVerFull.split("@").get(0).split("/").get(1)
var String sNewFW = transform("JSONPATH", "$.new_fw", ShellyAnnounce.state.toString)
var String myItem
switch sID {
case "shelly1-55521D": myItem = "Shelly1_01"
case "shellyswitch-5A4CE4": myItem = "Shelly2_01"
}
sendCommand(myItem+"_FWVer",sFWVer)
sendCommand(myItem+"_NewFW",sNewFW)
sendCommand(myItem+"_IP",sIP)
end