[SOLVED] Rules vs Scripts?

Ah, different members of a Group with different settings? No, I don’t think that is possible without rules.

1 Like

Do you think it will be possible If I set all rollershutters (including the bedroom) to open by 30%?

Maybe. Share your Items configuration and we’ll see…

This is an example rule I would like to replace with a script or group, because I had occasions the rule didn’t work properly (and from tonight all my rules stopped working altogether, for no apparent reason. Even simple rules with one command).

rule "Good Night"
when
    Item BedLeft_Switch3 changed from OFF to ON
then
    sendCommand(Entrance_Switch2, OFF)
    sendCommand(Entrance_Switch4, OFF)
    sendCommand(Bathroom_Switch2, OFF)
    sendCommand(Bathroom_Switch3, OFF)
    sendCommand(Bathroom_Switch4, OFF)
    sendCommand(Kitchen_Switch1, OFF)
    sendCommand(Kitchen_Switch2, OFF)
    sendCommand(SalonTV_Switch1, OFF)
    sendCommand(SalonTV_Switch2, OFF)
    sendCommand(SalonTV_Switch4, OFF)
    sendCommand(SalonDesk_Switch1, OFF)
    sendCommand(Balcony_Switch1, OFF)
    sendCommand(Balcony_Switch2, OFF)
    sendCommand(Bedroom_Switch2, OFF)
    sendCommand(Bedroom_Switch4, OFF)

    sendCommand(BedRight_Dimmer3, 100)
    sendCommand(SalonWindow_Dimmer3, 100)
    sendCommand(SalonDesk_Dimmer3, 100)
    sendCommand(SalonBalcony_Dimmer1, 100)
    sendCommand(SalonBalcony_Dimmer2, 100)
    sendCommand(Balcony_Dimmer3, 0)
end

Right, that rule is in your OP too. But we need to see your Items configurations in order to properly determine how to setup the mappings.

My God, OpenHAB is really confusing me today. All my Rules started working again :dizzy_face:
Is this common behavior, that things stops working and then starts working again after a few hours?

No, this is not typical. You’d need to look through the logs to determine what is causing this. Since you are using a Pi, you’re probably using an SD card, which may need to be replaced. Have you removed the ghost nodes?

Here you go, but don’t expect much unless you’ve cleaned up your Z-Wave network.

from core.rules import rule
from core.triggers import when

@rule("Good Night")
@when("Item BedLeft_Switch3 changed from OFF to ON")
def good_night(event):
    events.sendCommand("Entrance_Switch2", "OFF")
    events.sendCommand("Entrance_Switch4", "OFF")
    events.sendCommand("Bathroom_Switch2", "OFF")
    events.sendCommand("Bathroom_Switch3", "OFF")
    events.sendCommand("Bathroom_Switch4", "OFF")
    events.sendCommand("Kitchen_Switch1", "OFF")
    events.sendCommand("Kitchen_Switch2", "OFF")
    events.sendCommand("SalonTV_Switch1", "OFF")
    events.sendCommand("SalonTV_Switch2", "OFF")
    events.sendCommand("SalonTV_Switch4", "OFF")
    events.sendCommand("SalonDesk_Switch1", "OFF")
    events.sendCommand("Balcony_Switch1", "OFF")
    events.sendCommand("Balcony_Switch2", "OFF")
    events.sendCommand("Bedroom_Switch2", "OFF")
    events.sendCommand("Bedroom_Switch4", "OFF")

    events.sendCommand("BedRight_Dimmer3", "100")
    events.sendCommand("SalonWindow_Dimmer3", "100")
    events.sendCommand("SalonDesk_Dimmer3", "100")
    events.sendCommand("SalonBalcony_Dimmer1", "100")
    events.sendCommand("SalonBalcony_Dimmer2", "100")
    events.sendCommand("Balcony_Dimmer3", "0")
1 Like

In the absence of your Item configuration, I’ll do some guessing based on this bit of your original rule:

    sendCommand(BedRight_Dimmer3, 100)
    sendCommand(SalonWindow_Dimmer3, 100)
    sendCommand(SalonDesk_Dimmer3, 100)
    sendCommand(SalonBalcony_Dimmer1, 100)
    sendCommand(SalonBalcony_Dimmer2, 100)
    sendCommand(Balcony_Dimmer3, 0)

Presumably your Items are Dimmer types, which take a percentage value. I guess Rollershutter type would also work here.

Let’s make a rollershutter group called gRollershutters, by adding the following to your Items file:

Group gRollershutters

(You can do all sorts of fancy things with this group, but lets keep it simple for now).

Your Items now need to be added to the group. Do this by adding (gRollershutters) to each Item. For example, assuming your Items are Dimmer types:

Dimmer BedRight_Dimmer3 "BedRight_Dimmer3" (gRollershutters) { channel="....."  }
Dimmer SalonWindow_Dimmer3 "SalonWindow_Dimmer3" (gRollershutters) { channel="....."  }
Dimmer SalonDesk_Dimmer3 "SalonDesk_Dimmer3" (gRollershutters) { channel="....."  }
Dimmer SalonBalcony_Dimmer1 "SalonBalcony_Dimmer1" (gRollershutters) { channel="....."  }
Dimmer SalonBalcony_Dimmer2 "SalonBalcony_Dimmer2" (gRollershutters) { channel="....."  }
Dimmer Balcony_Dimmer3 "Balcony_Dimmer3" (gRollershutters) { channel="....."  }

So now we have a group gRollershutters which contains the above Items.

In your Sitemap you can add a Switch, and attach it to gRollershutters, and use mappings to alter what the Sitemap sends when you press a particular button:

Switch item="gRollershutters" label="All rollershutters" mappings=[30="OPEN", 0="CLOSE"]

The above code will add the following widget to your Sitemap. Pressing OPEN will send 30 to the gRollershutters group, which in turn will send it to all the group members. Pressing CLOSE will send 0.

image

You can play around with the mappings, and add more buttons if you want. For example, the below sets up three buttons for 100% (fully open), 50% (half open/closed) or 0% (fully closed)

Switch item="gRollershutters" label="All rollershutters" mappings=[100="FULL", 50="HALF", 0="CLOSE"]

image

1 Like

I actually moved my Raspberry Pi system from the SD card to a USB connected SSD a few weeks ago.

The ghost nodes are still there. I tried removing them from the controller with HABmin and PaperUI based on your explanation, but they reappeared after an Inbox search with the Zwave binding.

I downloaded Simplicity Studio 5 for mac, but I found out it doesn’t support the PC controller.
So I’m now trying to install a Windows virtual machine on my mac and will try to install Simplicity Studio on that system.

This is awesome. Thank you so much for this example script!!!
Using it I could most likely reproduce similar or different scripts myself (Hoping I can succeed in being a copying monkey :monkey_face: ).

To use this script, do I need to create a new .rules file in the /etc/openhab2/rules folder and paste this script into it?
Or do I also need to install the dependencies from the Eclipse Marketplace you mentioned in your earlier post?

Read through the documentation for the helper libraries…

The add-ons in the marketplace are not ready due to wind damage after a storm this weekend. I plan to have them out this weekend. For not, use the beta Jython add-on…

If you run into trouble or have questions, just ask!

You can download just the PC Controller app from SiLabs. There are posts in the forum… sorry, on my phone.

1 Like

Thank you so much, @hafniumzinc !!! That’s a great explanation for noobs like me!!!

My blinds items are indeed set as Rollershutters. I took a photo of one of my blinds item configuration for you to see. The others are set in the same way.

Ok. I have the PC controller installed and running.
Is there a way to force remove nodes from my controller?
I was able to set them as FAILED, but when I press REMOVE, the app asks me to press the exclude button on the node (which I no longer have).

Ah, it’s configured via PaperUI. I don’t have much experience, though it looks like you have a Parent groups field which presumably can have the name of the gRollershutters group? Either way, principal stays the same - hopefully it’s useful!

1 Like

Have you tried pressing “Remove Failed”

1 Like

Remove is for exclusion. You will need to use Remove Failed. You first need to send NOPs to the device (the number field is for the node number to send the NOP to), then Is Failed, then you can Remove Failed. If the controller already knows the device is failed, you may be able to go directly to Remove Failed.

In case you are not aware, OH should be shutdown when inserting/removing the controller.

1 Like

Excellent!
For a few nodes I had to run the NOP, FAIL, REMOVE commands a few times, because they failed to be accepted, but it seems I eventually managed to remove all ghost nodes :))))))))

I will check the behavior of my OpenHAB system over a longer period of time, but, so far, it appears to be reacting much faster.

Thank you so much for all the help from everyone!!! @5iver @Nick_Wilkinson @Uwe_Samer @hafniumzinc @Magnus :pray: :pray: :pray: :pray:

If the system keeps reacting consistently now that the ghost nodes are gone, I guess I will just leave my current rules as they are.

Just wanted to say that since removing the ghost nodes, OpenHAB has been working phenomenally and consistently! :slight_smile:
All rules and Siri Commands are working great and with no lag.
Thank you very much, everyone.
I’m happy to say this thread is solved :pray::pray::pray:

3 Likes