Please send basic rule examples (CLOSED)

Just trued to create a text rule didn’t run I used this corn time but the times under looked wrong it was just ment to run and turn a light off never triggered

EDIT STUPID 24HOUR CLOCK MY MISTAKE :frowning:

As you can see one of my rules are disabled it gets enabled by another rule once it’s enabled and it runs it disables itself again


If you run RULE 1 it shuts down a computer once that’s done it enables RULE 2 , RULE 2 then runs and disables itself when finished running

I can’t help you there. All my rules are text based in .rules files. I haven’t used the paperUI rules engine.

I’m sure someone else can help though.

1 Like

thank you Saracen i was just going to ask if you could help with a different post

realised you were the person who already replyed

have you any more ideas what is going on in my other post would a text based rule help instead of the paper ui rule engine

A text-based rule would be easier for other people on this forum to help debug. Better for you for a learning point of view too.

I’m basically only a beginner too but it’s all a little clearer than when I started out!

1 Like

I HAVE CREATED MY FIRST TEXT RULE IT WAS SET TO RUN WITH CRON TIME TO ONLY TURN A LIGHT OFF BUT IT WORKED THANK YOU VERY MUCH ON THAT.

i wrote in caps and didnt want too change it after couldent post without some small letters

1 Like

How long have you been running openhab? & how big is your setup?

do you think you could help me with a real rule it could replace 6 rules of mine if you could?

what im after is a single rule that

dims my light every hour starting at 8PM ending at 10% at 11PM

i was thinking to use cron like you said but get it to stop somhow at 11PM

I dont want the light to dim if its already dimmed more than the sent command (say its set 20 and the command was set to dim to 40 dont dim as it would make the bulb brighter when not wanted)

Not sure how big my setup is compared with others. I control everything from, lights, shutters and security to Christmas tree lights and a controller for a a snake terrarium (heater, lights, humidity, feeding times etc).
. I started about a year ago with openHAB1. |t’s come a long way since then.

With regard to your rules, why not have a go at writing them yourself and if they don’t work, post them up here and I’m sure some of the people here would be more than happy to help.

They’ve helped me a lot.

im not sure how you seperate the rules in a single file

i would add them on top of each other and save them as light dimming schedual.rule

do you just put a space and the next rule below

Thanks for your help Saracen i will update my progress here

We know. You have proven this in your other posts. That is why I’m happy to help. :slight_smile:

Look at some of the Design Pattern postings which have lots of explanations. There are some simple example rules at the bottom of the Rules doc Opus posted.

The demo setup also comes with some working rules. Sadly, I’m not entirely certain how to install the Demo setup after you are up and running. You can choose Demo from the list of packages when you first start up a fresh OH install.

I’ll open an issue on the docs to indude some super simple examples in the Beginner’s Tutorial.

This is not supported in the Rules DSL. That is a new feature of the Experimental Rules Engine.

Yes, that is how you do it.

I have made a lot of posts and alot of them simple,
I just hope I’m not annoying everyone with my simple questions. I do think I’m learning slowly tho

As for the demo version I think I will spin up a quick Vm and install openhab to steal the demo files to have a learn from them

And as for the beginner code in the docs it would be extremely helpful it’s impossible to understand big blocks of code even if it is simple.
I have looked through alot of the docs but it is deffinitly scary and overwhelming for beginners (I would help myself but I don’t know enough to help)

I have managed to get two rules in one file it worked I’m just having problems at the moment with a single rule.
I have created a new post to leave this open for more simple examples

We only get annoyed when you show no interest in trying to learn or make it work yourself. You have proven to be willing to do the work so we are more than happy to help as much as we can.

I might recommend going through one of the open courseware type programming courses. MIT offers a good beginner’s one based around Python. It is free and it might give you more confidence in tackling the coding aspects of Rules.

Even though the language is different, it will teach a lot of concepts that carry over to all programming languages which you will need even in humble old OH Rules.

I’m more than happy to learn about systems in my house I hate running things I don’t understand if you don’t once something goes wrong its impossible to fix or even maintain.

I might have alook at that course you linked

I pick stuff up pretty quick I think I can manage the the simple code rules by just getting a few up and running and copy and paste my own code and edit from there. (I have set the log to continuous picking up alot from the watching commands and items change)

Probably not the more complex coding (I hear of trained programmers struggling to learn openhab :o)

I have opened threads about more complicated stuff that I am leaving until more skilled (it sometimes takes me a while to reply to threads I open while I get my head around what’s been said)

Their problem tends to be more caused by the fact that the language Rules are written are simplified in ways that take away features they are used to using. It forces them to think about how to code their rules differently from what they are used to and many are incapable or unwilling to do so. Luckily we have a way for them to code using one of several traditional languages.

1 Like

This rule waits for an event (opening a door in this example) and then stores that time in another item. It will also send an email if you have setup email in yr openhab:

// Backdoor
rule "Backdoor last opened"
when 
Item Backdoor changed to OPEN
then
BackdoorTime.postUpdate( new DateTimeType() )
sendMail("xxxxxx@gmail.com", "Deur Alarm", "Back-door open")
end

So you need two items: Backdoor, that is configured as a contact and BackdoorTime, configured as DatTime

DateTime  BackdoorTime "Backdoor last open [%1$tm/%1$td %1$tH:%1$tM]" <door2> (Your groups)

Contact Backdoor   "Backdoor [%s]" <door2>  (Your group) {mqtt="<[mosquitto:home/GF/Living/terracedoor:state:default]"}
1 Like

Why you don‘t read all Examples ? Here is enough Stuff to learn…

I have been reading the examples i was looking for more simple examples like i said earlyer in the post

Another rule (if some people are interested to calculate some values out of multiple sensors) - Using configuration files.

I have some solar panels (sma_power in watts) and the energy consumption (energymeter_kw in kw) of my house. Energy consumption can be negative (when I produce more than I consume).

To calculate the real energy consumption of my house, I have to add the solar panels to my consumption.

First I have added an item (in energymeter.items)

Number energymeter_kw_real "EM Power Real [%.3f kW]" <energy> (Energy, EnergyMeterSub)

Then I’ve added a rule

rule "Calculate Real EM Power"
when
       Item sma_power received update
then
       var Number e = energymeter_kw.state
       var Number f = sma_power.state
       e = e + f / 1000
     sendCommand(energymeter_kw_real, e)
end

energymeter_kw_real is updated to ( energymeter (kw) + sma_power/1000 (w)) and is in kW

(Nice job OpenHab2’s team! It’s hard to find the way to do things, but it’s limitless :slight_smile: )

Thanks for posting the example. In the future, to preserve the formatting of your code you can use code fences instead of quotes.

```
code goes here
```

Thanks, changed the text

1 Like