*Issue of the topic:
I need help creating a rule for sending a play command to MPD when I press the first button of my hue dimmer switch (setting up a second one for stop should be easy once this works).
I created this rule using a blockly script for the action:
A Thing will never have a status of “1000.0”. It will be ONLINE, OFFLINE, ERROR, INITIALIZING, etc.
Do you mean to check the event that triggered the rule to see if it’s “1000.0”?
It occurs to me that I don’t know how to do that in Blockly. In Rules DSL event will have the value from the channel trigger event that caused the rule to run. In other languages it would be event.event or something like that.
I had a look at Rules DSL and i guess i have a script that can work (with the help of ChatGPT).
I tested the dimmer switch and the MPD-remote separately. The switch works but the MPD-remote does only work in the GUI:
I’ve yet to see ChatGPT produce a working openHAB rule. Always review every line of code against the docs.
Beyond being way more complicated than necessary, the code it generated isn’t sending a command to an Item, it’s using executeCommandLine to call an external program called mpc. I’t also probably a problem to use the reserved word “switch” as a variable name. There’s no such thing as “lastEvent” and if there were, it wouldn’t be a “dimmerSwitch”.
While this rule is less bogus than most, it does not break ChatGPT’s perfect zero when it comes to generating working openHAB rules. You’d have to know enough about coding OH rules to correct this code as you would need to write it in the first place without ChatGPT.
What you need is ultra simple though. First, please please please don’t skip the Getting Started Tutorial and the docs. Please do refer to the many thousands of example rules here on the forum.
Keep your original rule with it’s trigger. Remove the Script Action and replace it with a new one. Your choice. The contents will be very simple:
If you want to stick with Blockly, use an Inline Script block with the following: