I’m new to OH but I’m very excited by the prospects. The first major hurdle I’m having is getting my triggers to work. I have a WOL script that I’d like to trigger with a switch, I’m using the UI editor. The script works correctly when executed in the script editor, but I cannot get the trigger to run the script either from a page or a siteMap via iOS.
triggers:
- id: "1"
configuration:
itemName: wol_entertainment
state: ON
previousState: OFF
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: |-
val actions = getActions("network", "network:pingdevice:cea6b998bb")
if (actions === null) {
logInfo("actions", "Actions not found, check thing ID")
return
} else {
// Send via MAC address
//actions.sendWakeOnLanPacketViaMac()
logInfo("triggered", "WOL action triggered")
actions.sendWakeOnLanPacket() // deprecated
// Send via IP address
//actions.sendWakeOnLanPacketViaIp()
}
type: script.ScriptAction
The event generated by the switch item is shown in the log:
[TRACE] [openhab.event.ItemCommandEvent ] - Received event of type 'ItemCommandEvent' under the topic 'openhab/items/wol_entertainment/command' with payload: '{"type":"OnOff","value":"ON"}'
No, that’s the event sent from your UI.
The Item command event should be found in your events.log, to make sure the chain is complete.
That’s a state rule trigger, not a command trigger. These are not the same thing.
You should look into why your code and screenshot are different, some confusion?
@rossko57 , @Oliver2 – thanks for the reply, I guess I had been messing about with the ItemStateChangeTrigger and hadn’t saved. I’ve not set it back to the ItemCommandTrigger to no avail. Are there API references somewhere that I’m missing? I’m a software dev so I’d much rather read through a ref than try to figure this out from the tutorials/UI.
@rossko57 , the log lines in events.log look similar to those in the console:
[TRACE] [openhab.event.ItemCommandEvent ] - Received event of type 'ItemCommandEvent' under the topic 'openhab/items/wol_entertainment/command' with payload: '{"type":"OnOff","value":"ON"}'
[TRACE] [openhab.event.ItemStateChangedEvent ] - Received event of type 'ItemStateChangedEvent' under the topic 'openhab/items/wol_entertainment/statechanged' with payload: '{"type":"OnOff","value":"ON","oldType":"OnOff","oldValue":"OFF"}'
Okay, well changed to NULL and added those lines, but again - the script is not running. I can run it from the UI using the “play” button and see my logInfo lines and WOL packet sent. The problem here is that the trigger is not executing.
Just so we’re clear, here is exactly what I did: Created an Item of type Switch named wol_entertainment and added it to my “LivingRoom”. I then added widgets in a page and added the item to my sitemap.
Then, I used the UI to build the rule. This should work, correct? Am I missing something?
Those look weird, but then nobody runs with TRACE on events.
But it looks like commands do happen.
Make a new rule, simple as possible. Trigger from ANY command to your Item, have the script just be a logInfo announcement.
I’m speculating this rule has a corrupt trigger somewhere.
[TRACE] [openhab.event.ItemCommandEvent ] - Received event of type 'ItemCommandEvent' under the topic 'openhab/items/test_switch/command' with payload: '{"type":"OnOff","value":"ON"}'
[TRACE] [openhab.event.ItemStateChangedEvent ] - Received event of type 'ItemStateChangedEvent' under the topic 'openhab/items/test_switch/statechanged' with payload: '{"type":"OnOff","value":"ON","oldType":"OnOff","oldValue":"OFF"}'
Ah, some progresss. I set the log level of org.openhab and openhab.event to DEBUG and received:
[DEBUG] [re.automation.internal.RuleEngineImpl] - The trigger '1' of rule 'test_rule' is triggered.
[DEBUG] [re.automation.internal.RuleEngineImpl] - Rule engine not yet started - not executing rule 'test_rule',
I’ll look into restarting/enabling the rule engine.
There’s a problem worth fixing before attempting diagnosis of other things. There are a number of posts about similar missing logs, so far as I can make out happens sometimes after OH2->OH3 upgrade, to do with logfile locations perhaps.
FWIW, this was solved by installing misc/openhab (v3.2.0) via bsd ports.
I assume the same could be assumed for pkg installs using the misc/openhab package.