Hello everyone,
I recently did quite a jump on my system by impletenting a rules following the design pattern made by @skatun (see Magical light scenes). However, I was not quite pleased with the way some of the things are handled there. I did at first go with the Map approach to transform different states, but since I want to my scenes to include not only the lights them selves being turned on, but also passed a brightness and a color, I am trying a new approach.
Instead of using three .map files like the following. The number represents the switch state in all files.
// livingroom_scene.map
0=OFF
1=ON
2=morning
// livingroom_brightness.map
0=0
1=100
2=80
// livingroom_color.map
0=0
1=40
2=100
I was thinking of using a .json file, in order to be able to easily set scenes and also tell the values apart:
{"lr":
{"0": {"mood": "OFF", "brightness": "0", "color": "40"},
"1": {"mood": "ON", "brightness": "100", "color": "0"},
"2": {"mood": "night", "brightness": "50", "color": "100"},
"3": {"mood": "morgen", "brightness": "100", "color": "400"},
"4": {"mood": "arbeit", "brightness": "100", "color": "0"},
"5": {"mood": "dinner", "brightness": "70", "color": "40"},
"6": {"mood": "tv", "brightness": "50", "color": "40"}
}}
While this at first seemed like a rather smart approach, I now can’t process the file.
In my rule I am trying to set value for the brightness like so.
val strHelligkeit = transform("JSONPATH", "$." + roomName + "." + triggeringItem.state , "" + triggeringItem.state)
roomName
in this scenario being lr
and triggeringItem.state
being the scene number. strHelligkeit
is German for strBrightness
, but what kind of lunatic would stick one scheme when namig variables. I guess that will not work, because I can’t clarify where to search for triggeringItem.state
within the .json. logInfo("Brightness", strHelligkeit)
always returns the State of the triggering item, rather then an actually transformed value.
Is there a way to achieve my setup in this kind of way or should I stick to creating multiple .map files?