I’m game to try again. I removed my text rule (putting it someplace safe) and then re-created the UI rule that triggers on the same event.
I created the new Script Action and put a chunk of the code from the DSL rule in to it:
configuration: {}
triggers:
- id: "1"
configuration:
thingUID: mqtt:topic:feefb09ab0:b17c7192c7
channelUID: mqtt:topic:feefb09ab0:b17c7192c7:MasterBedroomDesk_switch_action
type: core.ChannelEventTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: >
switch(receivedEvent) {
case 'toggle': {
if (MasterBedroomDesk_lights_MasterBedroomDesk_switch_state.state == ON) {
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_state, OFF);
}
else {
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_state, ON);
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_brightness, 254);
}
}
}
type: script.ScriptAction
And that worked properly. Yay!
I then tried to put the rest of the rule back in place:
configuration: {}
triggers:
- id: "1"
configuration:
thingUID: mqtt:topic:feefb09ab0:b17c7192c7
channelUID: mqtt:topic:feefb09ab0:b17c7192c7:MasterBedroomDesk_switch_action
type: core.ChannelEventTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: >
switch(receivedEvent) {
case 'toggle': {
if (MasterBedroomDesk_lights_MasterBedroomDesk_switch_state.state == ON) {
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_state, OFF);
}
else {
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_state, ON);
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_brightness, 254);
}
}
case 'brightness_down_click': {
if (MasterBedroomDesk_lights_MasterBedroomDesk_switch_state.state == ON) {
var currentBrightness = MasterBedroomDesk_lights_MasterBedroomDesk_switch_brightness.state as Number;
var newBrightness = currentBrightness - 32;
if(newBrightness < 2) {
newBrightness = 2;
}
if(newBrightness != currentBrightness) {
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_brightness, newBrightness);
}
}
}
case 'brightness_up_click': {
if (MasterBedroomDesk_lights_MasterBedroomDesk_switch_state.state == ON) {
var currentBrightness = MasterBedroomDesk_lights_MasterBedroomDesk_switch_brightness.state as Number;
var newBrightness = currentBrightness + 32;
if(newBrightness > 254) {
newBrightness = 254;
}
if(newBrightness != currentBrightness) {
sendCommand(MasterBedroomDesk_lights_MasterBedroomDesk_switch_brightness, newBrightness);
}
}
}
}
type: script.ScriptAction
Those two new case statements work perfectly in the rules DSL. They fail here, with two errors:
1. Type mismatch: cannot convert from int to BigDecimal; line 17, column 722, length 1
2. Type mismatch: cannot convert from int to BigDecimal; line 29, column 1221, length 3
Those are the lines with the greater than or less than check:
if(newBrightness < 2) {
if(newBrightness > 254) {
The Internet suggested the BigDecimal.valueOf() would fix it, but that doesn’t exist, and import doesn’t seem to work here. So, I’m stuck with UI Rules, but it works in a text file.
Any suggestions on where I should look to get unstuck?