Hi,
I just try to code a simply rule to add my Xiaomi cube …
Actual the rule is:
rule "Aqara Cube event"
when
Channel 'mihome:sensor_cube:158d00029a93ff:action' triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "MOVE": { logInfo("diverses.rules", "MOVE (Angel:{}",Xiaomi_Cube_Angle_01.state)
...
...
I already add a (virtual) switch to decide, if the action from the cube should be realy executed.
Switchname is: vSwitch_Cube
I just want to add that when a “action” from the cube was triggered, the vSwitch_Cube is also checked that his state is “ON” (when “OFF”, do no action form the defined cube actions)
Can I realise this in the same line with an “and”? How? With an additioally “if …”, OK, this will also work. …
I try this, but (clear) is not working…
rule "Aqara Cube event"
when
Channel 'mihome:sensor_cube:158d00029a93ff:action' triggered and Item vSwitch_Cube = ON
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case ...
...
...
I know how to add “and” or “or” in rule like:
…
Item Switch_1 changed from ON to OFF or Item Switch_2 changed from CLOSED to OPEN
…
But how check if the state is “ON” (without an change from … to …) ?
The rule has two parts, the triggers and the code which is executed.
The trigger part is a list of every event that will start execution of the rule. There is no “but only if” in this part.
If there would be an and to link conditions, the rule would only trigger if both triggers happen at the same time (which is very unlikely ever to happen).
So instead you have to check the state within the executed code:
rule "Aqara Cube event"
when
Channel 'mihome:sensor_cube:158d00029a93ff:action' triggered
then
if(vSwitch_Cube.state != ON)
return; // stop rule immediately
var actionName = receivedEvent.getEvent()
switch(actionName) {
case ...
...
...
Hi Martin, I thumbs in your examples that interested me
Can you better explain the virtual switch purpose? How do you make use of it?
Perheaps like as variable to store item state? How do you use it?
I’m sorry,
can’t find my “Old” solution, I think it was a “simple” “if” construct inside an rule …
Actuall I use the “Global” solution from Udo inside the Cube-rule, it works fine:
“Execute the cube movement -action only, when the vSwitch_Cube.state is ON”:
(in 5th and 6th line)
rule "Aqara Cube event"
when
Channel 'mihome:sensor_cube:158d00029a93ff:action' triggered
then
if(vSwitch_Cube.state != ON)
return; // stop rule immediately
var actionName = receivedEvent.getEvent()
switch(actionName) {
case ...
Can I ask you to submit your entire code?
I hardly understand the logic behind the fact that, for me, every “action” trigger differently, means for example different light lamps
Perheaps reading the entire example would help me
Thanks so much
Ok, very good example, really so usefully especially for the if/then/else conditions inside that confim me the right way considered my code developed like this
rule "Aqara Cube Control"
when
Channel "mqtt:topic:mosquitto:testthecube:action" triggered // In abbinata al valore trigger=true nella configurazione del channel
then
logInfo("test_AqaraCube rules", " Channel triggerd: {} ", receivedEvent.getEvent) // test
// logInfo("test_channel.rules", " Channel triggerd: {} ", receivedEvent) // test
var actionName = receivedEvent.getEvent()
logInfo( "CUBO", "INFO: Channel Event = '{}'", actionName )
switch(actionName) {
case "shake": {
if (Mobile_Stato.state.toString != "ON") // != vuol dire Not Equal
Mobile_Stato.sendCommand(ON)
else
Mobile_Stato.sendCommand(OFF)
}
case "flip90":{
if(Cucina_Stato.state.toString != "ON")
Cucina_Stato.sendCommand(ON)
else
Cucina_Stato.sendCommand(OFF)
}
case "flip180":{
if(Shelly_Switch.state.toString != "ON")
Shelly_Switch.sendCommand(ON)
else
Shelly_Switch.sendCommand(OFF)
}
case "rotate_left":{
if(GTutteLeRampe.state.toString !="ON")
GTutteLeRampe.sendCommand(ON)
else
GTutteLeRampe.sendCommand(OFF)
}
case "rotate_right":{
if(SW_Ikea_Ingress.state.toString != "ON")
SW_Ikea_Ingress.sendCommand(ON)
else
SW_Ikea_Ingress.sendCommand(OFF)
}
case "slide":{
if(Toilet.state.toString != "ON")
Toilet.sendCommand(ON)
else
Toilet.sendCommand(OFF)
}
default:
{ logInfo("xiaomi", "No match found for {}", actionName)}
}
AqaraCubeAction.postUpdate(actionName)
end
Perheaps, better reading the example I find a reason for the vSwitch item in your code
Is this binding related? Better, is this gateway related so that you have to check the CUBE status at any time?
I didn’t understand it before because my code is MQTT and Zigbee framework dependent.
Also, this explain the different tag I have on my Awara Cube
Am I right?