Please send basic rule examples (CLOSED)

LET ME PUT THIS CLEAR I DO NOT WANT YOU ALL TO DO MY WORK FOR ME IM TRYING TO LEARN

Could you all please send me some example rules with explanation I’m trying to learn how to build my own text based rules (it seems like PAPERUI can’t do some things needed)

i have already read through the rule docu (theres alot to take in there)

And need too start somewhere but haven’t a clue

Please send simple rules with notes explaining how they work and what they do

I would like them easy to edit so I can try them in my setup and edit and add from there

Rule 1) A dim light to 50 at 8pm but only if it’s already above 50 brightness (i have done this rule in paperui doeset seem too work)

Rule 2 when something changes turn something off

Start with reading here.

1 Like

hi opus thanks for the link

i have already had a read off the rules section and to be honest there was that much information there it was just overwhelming

what i need is example rules

like something changes so turn off something

if i had example rules and i edited them to work with my setup i could see how they run learn some more and keep reading the link you sent me once i actually understand whats happening

have a look into the OpenHAB1 Rules examples

1 Like

thanks again opus but they seem like complicated rules (i cant code big blocks of text like that scare and confuse people who arnt used too it it might aswell be in german or something)

im after a starter simple rule too play with and learn from could you send me one of your simple rules

eg

button press light turns on

or its some time of day dim light to whaterer but only if whatever

Normally an Item (in this case as switch or button) would be linked to a Thing (the light), that way the press on that Item would turn the ligth on directly. No rule needed!

rule "Basic rule"
when
Item TestSwitch changed
then
sendCommand(LigthSwitch, ON)
end

1 Like

Thanks Opus i realy appretiate that

i have created all my things and items using paperui (Auto discover)

if i create a text rule can i use the names generated via paperui or do i need to create an text items file first

You can use the Items and Things created automatically!

i have had a quick edit of what you sent me i dont plan on using this just as a lesson does this look right too you ?

rule “MY FIRST RULE”
when
Item Movie_Mode_Trigger changed
then
sendCommand(Light1_Brightness, 50)
end

:+1:

Couple more questions

  1. when adding the items ect you use the parts with the brackets and underscores not the name
  2. How would I add a second action ? (is my try below correct)
  3. how do you add a but only if ?

[EDITED]
rule "MY FIRST RULE"
when
Item Movie_Mode_Trigger changed
then
sendCommand(Light1_Brightness, 50)
sendCommand(Light2_Brightness, 0)
end

Like this. Where mySwitch is a Switch Item:


rule "MY FIRST RULE"
when
      Item Movie_Mode_Trigger changed
then
    if (mySwitch.state == ON) {
    sendCommand(Light1_Brightness, 50)
    sendCommand(Light2_Brightness, 0)
    }
end

I agree that a list of simple sample rules would help a lot of beginners. The OH1 examples are too overwhelming at first.

1 Like

let me try

rule "MY SECOND RULE"
when
Item Movie_Mode_Trigger changed
then
if (Light1_Brightness => 50) {
sendCommand(Light1_Brightness, 50)
sendCommand(Light2_Brightness, 0)
}
end

when movie mode is pressed it checks to see if the brightness is above 50 if it is it lowers lamp 1 to 50 and turns lamp 2 off ?

could you also explain why there are now {} brackets in your rule but the other rule didnt

Using the {} brackets is just the syntax (like in the German language, every noun beginning with a capital letter).
In this case the brackets contains the list of things that need to be done if the if-then clause is met.

if (this is true) {

do all this stuff within the brackets

}

Your more than or equal to to should be >=. . This is explained here

thanks Saracen i will have a look through that link when i understand a little more i feel slightly more comfy now

is there a text editor that helps with these things ?

how would you add times of day eg make something happen at 2PM ?

is it advisable to put more than one rule in a rule file i currently have 6 rules just for dimming 1 light everyhour and it doesent even work properly

VS code is great for editing rules and items etc.

All is explained in this thread here .

For a time expression:

Rule "Do something at 2.00pm or 14:00)"

when

	Time cron "0 0 14 1/1 * ? *"
	
then
       ...Do stuff...
end

You do not need to know how to make the cron expression for the time.
On cronmaker.com, you select your time (and other things like whether you want it to happen everyday or, for example, just at weekends), and then click Generate Cron expression. The resultant Cron format is the one to paste into your rule.
Don’t forget the quotation marks around the Cron expression as in my example.

0 0 23 1/1 * ? *

daily 11PM

Yes. (damn those Europeans with their 24 hour clock!)

it always anoys me trying to work out 24 hour times lol

how do you enable and disable rules from within a rule ?

im already closer to knowing how to do this thanks to all the help already

I’m not sure what you mean by disabling rules from within a rule?

Of course you can use an if…then statement to ignore a chunk of a rule if a condition is met.
Is that what you meant or something else?