I have written a rule but it seems not to function. I believe because of the json string, it appears as
"direction":"INCREASE"
So my guess is I need to some how remove all of the string other than INCREASE
My item is a string
17:15:22.808 [INFO ] [smarthome.event.ItemStateChangedEvent] - BedRoom1_AeoButton_Slide1 changed from {"direction":"DECREASE"} to {"direction":"INCREASE"}
My goal is to basically increase the light dimming by 10% if the json string returns ‘increase’
I thought I had it right
No errors! JSON path is installed.
Rule:
var Number percent = 0
rule "WallMote Dim Control"
when
Item BedRoom1_AeoButton_Slide1
then
val String json = (BedRoom1_AeoButton_Slide1.state as StringType).toString
val String type = transform("JSONPATH", "$._type", json)
if (type == "INCREASE") {
percent = LivingRoomDim1.state as Number
percent = percent + 10 // increase brightness by 10%
LivingRoomDim1.sendCommand(percent)
}
logInfo('myrule', json)
end
Seems I need to split but this doesnt work very well because I need to store either the INCREASE or DECREASE values.
var Number percent = 0
rule "WallMote Dim Control"
when
Item BedRoom1_AeoButton_Slide1 received update
then
val String json = (BedRoom1_AeoButton_Slide1.state as StringType).toString.split("\\W+").get(2)
val String type = transform("JSONPATH", "$._type", json)
if (type == "INCREASE") {
percent = LivingRoomDim1.state as Number
percent = percent + 10 // increase brightness by 10%
LivingRoomDim1.sendCommand(percent)
}
logInfo('myrule', json)
end
Well, my json string contains direction: increase and direction: decrease
I want to act on either of those…Im not familiar with if (someString.contains("target"))
The above rule works, but I need to a) limit the increases to 100% (it went over 100) and then incorporate the decrease but the transform only splits the increase.
It seems that there 0 or 100 of the percent are not limits, it will try and go to below 0 and above 100%
06:49:54.048 [WARN ] [arthome.model.script.actions.BusEvent] - Cannot convert '-10' to a command type which item 'LivingRoomDim1' accepts: [PercentType, OnOffType, IncreaseDecreaseType, RefreshType].
Is there a way to define percent as being only between 0 and 100?
Yep, it’s called a Dimmer type. It only accepts 0-100. The problem is your rule sending e.g. -10, which isn’t allowed.
Solution: only send commands 0-100
Write code with the effect of “if >100 make it 100”, etc.
@dastrix80 So, I forgot to ask… It sounds like you got the Wallmote slide functionality working. Was there another change needed to the binding to get it working?
Ill test this tonight. Unfortunately I need one of these rules for each button , alot of rules if you have alot of buttons! I’m sure Mark youll be able to consolidate them down using smarter logic given you’ve a few
rule "WallMote Dim Control Kitchen"
when
Item Kitchen_AeoButton_Slide1 received update
then
val String json = (Kitchen_AeoButton_Slide1.state as StringType).toString.split("\\W+").get(2)
val String type = transform("JSONPATH", "$.direction", json)
if (type == "INCREASE") {
percent_kit = KitchenDim1.state as Number
percent_kit = Math.min(percent_kit + 10,100) // increase brightness by 10%
KitchenDim1.sendCommand(percent_kit)
}
if (type == "DECREASE") {
percent_kit = KitchenDim1.state as Number
percent_kit = Math.max(percent_kit - 10,0) // decrease brightness by 10%
KitchenDim1.sendCommand(percent_kit)
}
logInfo('myrule', json)
end
Ive started to test it but I get this error. I assume this is because the item is null.
17:36:57.034 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'WallMote Dim Control Kitchen': An error occurred during the script execution: Could not invoke method: java.lang.Math.min(int,int) on instance: null
17:36:59.398 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'WallMote Dim Control Kitchen': An error occurred during the script execution: Could not invoke method: java.lang.Math.min(int,int) on instance: null
var Number percent_kit = 0
var Number percent_liv = 0
var Number percent_eav = 0
Updated it and now:
23:00:54.363 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'WallMote Dim Control Kitchen': 'IntValue' is not a member of 'java.lang.Number'; line 34, column 48, length 20