Jump to content

Recommended Posts

7 hours ago, jgab said:

 

Any value. This works:

Util.defTriggerVar("test",”home”)
rule("test==’home’ => lamp: on")
rule("test~=’home’ => lamp: off")
alt.
rule("!(test==’home’) => lamp: off") 

 

 

Thank you very much. 

 

Now i understand. 

Link to post
Share on other sites
  • Replies 2.6k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Note. The first ~2000 posts of this thread is mainly about EventRunner3 that is for the HC2. EventRunner3 is not developed further, but bugs are fixed as they are reported. For HC3, the version i

I've been playing with the HC3 a bit  (I don't own a HC3 but a friend has allowed me to remotely login to do testing - I'm very grateful for that). ...and I have made some progress with EventRunn

Here is another "style" of coding when using the EventRunner framework. @julesmartens needed help to code an alarm system. It's a bit complicated because he needs "full" and "ring" protection dur

Posted Images

Simple rule for turning on/off light in bathroom. We leverage the fact that if someone moves inside the bathroom when the door is closed we keep the light on until the door opens again.

HT = {
  bath = {
    light = 99,    -- Lamp that we turn on if we sense motion in bathroom
    sensor = 101,  -- Sensor that detects motion in bathroom
    door = 102.    -- Door sensor that tell us if bathroom door is closed/open
   }
}

Util.defvars(HT)
Util.reverseMapDef(HT) 

Util.defTriggerVar('inside',false)
rule("bath.sensor:breached => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door
rule("trueFor(00:05,bath.sensor:safe & !inside) => bath.light:off")  -- Turn off light after 5min, if state is not inside bathroom
rule("bath.door:breached => inside=false")                           -- Door open, set state inside to false

 

Edited by jgab
Link to post
Share on other sites
1 hour ago, jgab said:

Simple rule for turning on/off light in bathroom. We leverage the fact that if someone moves inside the bathroom when the door is closed we keep the light on until the door opens again.

HT = {
  bath = {
    light = 99,    -- Lamp that we turn on if we sense motion in bathroom
    sensor = 101,  -- Sensor that detects motion in bathroom
    door = 102.    -- Door sensor that tell us if bathroom door is closed/open
   }
}

Util.defvars(HT)
Util.reverseMapDef(HT) 

Util.defTriggerVar('inside',false)
rule("bath.sensor:breached => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door
rule("trueFor(00:05,bath.sensor:safe & !inside) => bath.light:off")  -- Turn off light after 5min, if state is not inside bathroom
rule("bath.door:breached => inside=false")                           -- Door open, set state inside to false

 

 

What’s mean ??

inside=bath.door:safe
Link to post
Share on other sites
53 minutes ago, Earybeongbeong7 said:

 

What’s mean ??

inside=bath.door:safe

Just setting the 'inside' variable to the state of the door (true or false)

Link to post
Share on other sites

Jan,
Because we are with two persons present my wife hates the light will switch of when I leave the bathroom.
shower in bathroom with door sensor, motion dont detect if some one takes a shower, if shower is free door = open:

Util.defTriggerVar('inside',false)
rule("bath.sensor:breached & => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door
rule("bath.sensor:safe & douche.door:safe => bath.light:on; inside=bath.door:safe") -- light stays on someone in the shower
rule("trueFor(00:05,bath.sensor:safe & douche.door:breached & !inside) => bath.light:off")  -- Turn off light after 5min, if state is not inside bathroom
rule("bath.door:breached => inside=false")  

Jan two pir's one outside and one inside to let the light on if second person is involved"

rule("landing.sensor:breached & bath.door:breached => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door
rule("bath.sensor:safe & douche.door:safe => bath.light:on; inside=bath.door:safe") -- light stays on someone in the shower
rule("trueFor(00:05,bath.sensor:safe & douche.door:breached & !inside) => bath.light:off")  -- Turn off light after 5min, if state is not inside bathroom
rule("bath.door:breached & landing.sensor:safe => inside=false")  
rule("bath.door:breached & landing.sensor:breached=> inside=!false")  
rule("bath.door:breached & bath.sensor:breached & landing.sensor:breached => bath.light:on; inside=bath.door:safe")  --second person in
how to count?

Please advice,
//Sjakie

 

If this works I can use it for more rooms.

 

Link to post
Share on other sites
10 hours ago, jgab said:

Just setting the 'inside' variable to the state of the door (true or false)

 

rule("bath.sensor:breached => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door

The state of the statement in the variable is saved as "true or false", right?

 

bath.door:safe > true

bath.door:breached > false

 

Is it stored differently depending on the status of the door?

 

For example, if the motion is violated but the door is open, will the value of "inside" be "false"?

 

Then

 

Do the two codes below mean the same thing? I wonder if they are theoretically the same.

rule("bath.door:breached => inside=false")
rule("bath.door:breached => inside=bath.door:breached")

 

Edited by Earybeongbeong7
Link to post
Share on other sites
15 hours ago, Sjakie said:

Jan two pir's one outside and one inside to let the light on if second person is involved"

rule("landing.sensor:breached & bath.door:breached => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door
rule("bath.sensor:safe & douche.door:safe => bath.light:on; inside=bath.door:safe") -- light stays on someone in the shower
rule("trueFor(00:05,bath.sensor:safe & douche.door:breached & !inside) => bath.light:off")  -- Turn off light after 5min, if state is not inside bathroom
rule("bath.door:breached & landing.sensor:safe => inside=false")  
rule("bath.door:breached & landing.sensor:breached=> inside=!false")  
rule("bath.door:breached & bath.sensor:breached & landing.sensor:breached => bath.light:on; inside=bath.door:safe")  --second person in
how to count?

Please advice,
//Sjakie

 

This is very difficult to get 100% right. I would say it's impossible to count in general. It could depend on how the bathroom look like. If there is enough of a "landing zone"  so you can tell that a new person entered without staying at the same place as someone else also inside it could work - but in general really tricky,.

One could try to rely on habits like double-flicking the light earn existing and there is someone still inside (in the shower) to tell the light to not close. However, these things are easy to forget.

6 hours ago, Earybeongbeong7 said:

 

rule("bath.sensor:breached => bath.light:on; inside=bath.door:safe") -- turn on light when sensor breached, also set state depending on door

The state of the statement in the variable is saved as "true or false", right?

Yes, :safe returns a boolean

 

6 hours ago, Earybeongbeong7 said:

 

bath.door:safe > true

bath.door:breached > false

Can't use > and < with booleans. (even though in theory 'true' should be bigger than 'false' ;-) )

6 hours ago, Earybeongbeong7 said:

Is it stored differently depending on the status of the door?

For example, if the motion is violated but the door is open, will the value of "inside" be "false"?

correct,

6 hours ago, Earybeongbeong7 said:

 

Then

 

Do the two codes below mean the same thing? I wonder if they are theoretically the same.

rule("bath.door:breached => inside=false")
rule("bath.door:breached => inside=bath.door:breached")

 

Nop,

The first rule sets 'inside' to false if door is breached  (door:breached == true)

The second sets 'inside' to true if door is breached (door:breached == true)

Link to post
Share on other sites
39 minutes ago, jgab said:
Quote

 

bath.door:safe > true

bath.door:breached > false

Can't use > and < with booleans. (even though in theory 'true' should be bigger than 'false' ;-) )

 


My meaning is wrong.

 

rule("bath.sensor:breached => bath.light:on; inside=bath.door:safe")

Is it correct to store "true" in "inside"?

 

rule("bath.sensor:breached => bath.light:on; inside=bath.door:breached")

Is it correct to store "false" in "inside"?

 

And

 

rule("bath.door:breached => inside=bath.door:breached")

 

I don't understand that "true" is stored in "inside".

 

Isn't "inside = bath.door: safe" storing "true" in "insde"?

 

Edited by Earybeongbeong7
Link to post
Share on other sites
4 hours ago, Earybeongbeong7 said:

 


My meaning is wrong.

 

rule("bath.sensor:breached => bath.light:on; inside=bath.door:safe")

Is it correct to store "true" in "inside"?

 

If the sensor is breached and the door is closed (safe) we set variable 'inside' to true.

If the sensor is breached and the door is open (not safe) we set variable 'inside' to false.

 

4 hours ago, Earybeongbeong7 said:

 

rule("bath.sensor:breached => bath.light:on; inside=bath.door:breached")

Is it correct to store "false" in "inside"?

 

This will set 'inside' to true when door is open - if door is open we don't know where the user is and we set the variable 'inside' to false.

 

4 hours ago, Earybeongbeong7 said:

 

And

rule("bath.door:breached => inside=bath.door:breached")

 

I don't understand that "true" is stored in "inside".

 

Isn't "inside = bath.door: safe" storing "true" in "insde"?

 

 

When door is opened (breached) we wan't to set variable 'inside' to false - like in the case with the sensor.

Link to post
Share on other sites

Is the code below correct what I understand?

 

The automation usability of this code doesn't matter.

 

I just want to understand the meaning of the code.

 

rule("Livingbath_sensor:safe & Livingbath_door:value => Livingbathlight:off")
rule("Livingbath_door:breached => Livingbathlight:on")

 

Does "Livingbath_door: value" read the current state even if there is no physical state change of the "door sensor"?

 

I know that the "trigger" of the "rule" works only when the physical state of the "door sensor" changes.

Link to post
Share on other sites
5 hours ago, Earybeongbeong7 said:

Is the code below correct what I understand?

 

The automation usability of this code doesn't matter.

 

I just want to understand the meaning of the code.

 

rule("Livingbath_sensor:safe & Livingbath_door:value => Livingbathlight:off")
rule("Livingbath_door:breached => Livingbathlight:on")

 

Does "Livingbath_door: value" read the current state even if there is no physical state change of the "door sensor"?

 

I know that the "trigger" of the "rule" works only when the physical state of the "door sensor" changes.

Yes, the HC2/HC3 always read the current state,

When a physical device changes state it immediately reports the value to the HC2/HC3. The HC2/HC3 stores the value in an internal database.

When the value is stored/updated the HC2/HC3 also generates a 'sourceTrigger' that scenes (and QAs) can react on

EventRunner3/4. reacts on those triggers and run the rules that are concerned.

fibaro.getValue(id, prop) reads the value from that database. So, we always get the latest reported value.

Livingbath_door: value is internally translated to a fibaro.getValue(Livingbath_door,"value")

 

A note. There is a difference between sensors on the HC2 and HC3. On the HC3 the "value" of a sensor is a boolean.

On the HC2 it is a number. 0 for safe and 1 for breached. This means that sensor:value on the HC2 returns a number and on the HC3 a boolean, for sensors.

However, sensor:breached and sensor:safe always return a boolean both on the HC2 and the HC3.

Link to post
Share on other sites
6 hours ago, jgab said:

Yes, the HC2/HC3 always read the current state,

When a physical device changes state it immediately reports the value to the HC2/HC3. The HC2/HC3 stores the value in an internal database.

When the value is stored/updated the HC2/HC3 also generates a 'sourceTrigger' that scenes (and QAs) can react on

EventRunner3/4. reacts on those triggers and run the rules that are concerned.

fibaro.getValue(id, prop) reads the value from that database. So, we always get the latest reported value.

Livingbath_door: value is internally translated to a fibaro.getValue(Livingbath_door,"value")

 

A note. There is a difference between sensors on the HC2 and HC3. On the HC3 the "value" of a sensor is a boolean.

On the HC2 it is a number. 0 for safe and 1 for breached. This means that sensor:value on the HC2 returns a number and on the HC3 a boolean, for sensors.

However, sensor:breached and sensor:safe always return a boolean both on the HC2 and the HC3.

 

 

Thank you very much for your answer. 

Link to post
Share on other sites
4 hours ago, Earybeongbeong7 said:

Hello.  Thanks to this, I am learning ER well.  Is there any way or example of using the profile in HC3 in the ER4 rule?

Well, you can trigger on profile changes.

When a profile is activated a trigger is posted

#profile{value=<profileId>}

So you can trigger like this

rule("#profile{value='$id'} => log('Profile %s is activated',id)")

So, you could activate and deactivate a set of rules depending on what profile is activated

profile_1_rules = { -- Rules associated with profile 1
   rule("@07:00 => log('Ping')"),   
   rule("@sunset-00:10 => log('Pong')")
}
self.EM.disable(profile_1_rules) -- disable rules at startup
 
profile_2_rules = { -- Rules associated with profile 2
   rule("@08:00 => log('Ping')"),   
   rule("@sunset => log('Pong')")
}
self.EM.disable(profile_2_rules) --disable rules at startup

rule("#profile{value=1} => enable(prof1_rules); disable(prof2_rules) ") -- Enable rules associated with profile 1 (and disable 2)
rule("#profile{value=2} => enable(prof2_rules); disable(prof1_rules) ") -- Enable rules associated with profile 2 (and disable 1)

rule("post(#profile{value=QA:activeProfile()})") -- Post current profile at startup so that we enable the right rules

 

Edited by jgab
Link to post
Share on other sites

in ER4. arming and alarms work differently from ER3 and the HC2.

We arm alarm partitions. Alarm partitions have names and ids.

There is a new function/property :alarm in ER4.

Ex. <partition id>:alarm will return the partition structure for partition with id 1

rule("log('Partition 1:%s',1:alarm)")

will print out the structure.

 

rule("log('Partition 1 armed:%s',1:alarm.armed)")
rule("log('Partition 1 breached:%s',1:alarm.breached)")

Will print the armed and breached status of partition 1

 

rule("1:alarm=true; log('Partition 1 armed')")
rule("1:alarm=false; log('Partition 1 disarmed')")

Will arm/disarm partition 1. 

An id of 0 will enable/disable all partitions.

 

One fields of a partition structure is '.devices' that is an array of all devices that belong to a partition.

This means that we can do this

rule("log('Is all devices in partition 1 safe? = %s',1:alarm.devices:safe)")
rule("log('Is any devices in partition 1 breached? = %s',1:alarm.devices:breached)")

and we also get triggers when partitions are enabled/disabled and breached....

 

 

Edited by jgab
Link to post
Share on other sites
2 hours ago, jgab said:

in ER4. arming and alarms work differently from ER3 and the HC2.

We arm alarm partitions. Alarm partitions have names and ids.

There is a new function/property :alarm in ER4.

Ex. <partition id>:alarm will return the partition structure for partition with id 1

rule("log('Partition 1:%s',1:alarm)")

will print out the structure.

 

rule("log('Partition 1 armed:%s',1:alarm.armed)")
rule("log('Partition 1 breached:%s',1:alarm.breached)")

Will print the armed and breached status of partition 1

 

rule("1:alarm=true; log('Partition 1 armed')")
rule("1:alarm=false; log('Partition 1 disarmed')")

Will arm/disarm partition 1. 

An id of 0 will enable/disable all partitions.

 

One fields of a partition structure is '.devices' that is an array of all devices that belong to a partition.

This means that we can do this

rule("log('Is all devices in partition 1 safe? = %s',1:alarm.devices:safe)")
rule("log('Is any devices in partition 1 breached? = %s',1:alarm.devices:breached)")

and we also get triggers when partitions are enabled/disabled and breached....

 

 

 

 

Is it correct that a profile such as a picture is controlled?

244A71B7-C72A-4855-8E5B-C5DF4C4FE6FD.png

 

fibaro.profile('activateProfile',Away=2)

 

Is there any er4 instruction that can utilize this??

Edited by Earybeongbeong7
Link to post
Share on other sites
7 hours ago, Earybeongbeong7 said:

 

 

Is it correct that a profile such as a picture is controlled?

fibaro.profile('activateProfile',Away=2)

 

Is there any er4 instruction that can utilize this??

 

v0,5fix18

 

rule("2:profile=true")

 

or

rule("away = QA:profileId('Away')")            -- Assign variable id of profile 'Away'
rule("$vacation == true => away:profile=true") -- Turn on profile Away if fibaro global 'vacation' is set to true

and then triggers type

 

Link to post
Share on other sites

Jan,

Will this work?

 Rule.eval([[hal.locatieGezin:isOn & hal.kamerBoven:isOff & hal.kamerBeneden:isOff =>
        1:alarm=true; log('Huis aanwezig armed'); 
        3:alarm=true; log('kamerBoven afwezig armed');
        4:alarm=true; log('kamerBeneden afwezig armed');
            ]])
Please advice,
//Sjakie
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...