Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Recommended Posts

Posted
On 11/14/2023 at 7:17 PM, jgab said:

Alarm rules

 

Alarm in the HC3 is implemented by Fibaro using the concept of partitions.

Partitions are armed and disarmed. Individual devices (typically sensors) belongs to partitions

and if a devices is breached that belongs to a partition, the partition is breached and we have an alarm.

 

In ER5 we have properties to query partitions for their state

<partition>:armed - returns true if the partition is armed - 0 means the house

<partition>:tryArm - will try to arm the partitions - 0 means the house

<partition>:isArmed - returns true if the partition is armed - 0 means the house

<partition list>:isAllArmed - returns true if all partitions are armed

<partition>:isDisarmed

<partition list>:isAnyDisarmed - returns true if all partitions is disarmed

<partition>:isAlarmBreached

<partition>:isAlarmSafe

<partition list>:isAllAlarmBreached - returns true if all partitions are breached

<partition list>:isAnyAlarmSafe - returns true if any partitions is safe

 

and properties to change the alarm states

<partition>:armed=true - arms the partition - 0 means the house

<partition>:armed=false - disarms the partition - 0 means the house

 

<partition>:tryArm is special as it will try to arm the partition/partitions and if it doesn't succeed because their

is a breached device in any of the partitions it will post an event that list the partitions and devices that are breached.

Note that the arming will continue and if not cancelled, the partition will be armed and at the same time breached because of

the breached devices.

 

To handle that, one can make a rule that trigger on the posted event,

Ex:

Please login or register to see this code.

 

To trigger a rule if there is a breached partition/home, it's easiest to trigger on the events generated (in the future there may be properties)

Please login or register to see this code.

 

Unfortunately, if a partition is armed using the web UI/Yubii app, we don't get any warning from the fibaro api before the partition is armed - maybe in the future...

@Sjakie @Neo Andersson did you use the alarm? if yes can you share your rules/config ?

 

  • Like 1
Posted (edited)
12 minutes ago, ChristianSogaard said:

@Sjakie @Neo Andersson did you use the alarm? if yes can you share your rules/config ?

 

Maybe i did get something wrong, but for me the alarm is working in thisw way, i just dont rely on the alarm's breach event..I am simply checking the same sensors that are in my Alarm setup. So user does not recognize any difference. He just presses the Alarm button On or Off.  So actually i am using the Fibaro Alarm functionality just because it is accessible from Yubii upper menu, and it is more convevient for user to use it, and it also has tha PINCODE functionality so i dont need to create my own. This way i haven't had ever any problems.

 

Please login or register to see this code.

Edited by Neo Andersson
Posted (edited)

I converted my alarm QA from ER4 into ER5 and only modified some triggers who where  different in ER5.

It's working as a charme, as you can expecting as it's delivered by Jan!

 

I have a wallplugs in the electrical cabinet ( as back up) "sleep" and "Arming

If we go to bed by phone or manual we activate sleep >> on

sleep:isOn activated arming:on

arming:on >> we are at home or we are awy >> GEO location by IPhone

disarming if we approach our apartment or kitchen.door opens and pir:breached for home alarm

home alarm outside windows and doors

home away all sensors

if appartment is't under alarm when we are at home we have a kind of protection if some open a door or sensor NOT from inside it will make noice to alert us.

 

 

 

I only have some difficulties that Yubii does't show some times the actual state. 

Jan what am I doing wrong?

I press one key and as result:

Please login or register to see this code.

 

Edited by Sjakie
added more info
Posted
11 minutes ago, Sjakie said:

I converted my alarm QA from ER4 into ER5 and only modified some triggers who where  different in ER5.

It's working as a charme, as you can expecting as it's delivered by Jan!

I only have some difficulties that Yubii does't show some times the actual state. 

Jan what am I doing wrong?

I press one key and as result:

Please login or register to see this code.

 

 

Would you mind share a little more of your  alarm scene.

Perhaps push notification to mobile ?

Posted (edited)

Please login or register to see this code.

In bases I have in each QA ER5:

send message is Telegram always relaiable to my mobile.

Telegram is a tiny version from 10@der

 

If alarm it will send5 messages so you notice something wrong

This I also use in ärmin"scene to inform me appartment armed or disarmed wich device is breached is due to our small apartment not up to date.

If you are interested I can send you the scene in pm

Please login or register to see this code.

 

Edited by Sjakie
Posted
3 hours ago, jgab said:

 

Yes you could. Or you could create a separate file u_myfuns

where you setup your own stuff

Please login or register to see this code.

 

and then back in function QuickApp:main(er) you do

SETUP(er) 

somewhere in the beginning - before you start to create rules.

 

You can use this approach to have a separate u_file where you define your rules outside main()

@ChristianSogaard does something like that with all his rules.

The important is just to pass the variable 'er' from QuickApp:main(er) to the other functions and in those functions setup the rule function etc.

Please login or register to see this code.

The drawback is that they need to be global to be accessible from the main file. One can limit the number of globals by having one global table with the functions

Please login or register to see this code.

and in main() do

Please login or register to see this code.

 

However, I'm thinking of building something like this into ER5...


 

have been short on time so only had a play with er5 until now but today I made the switch at home . I don’t have hundreds of rules or not doing anything complex but also thought to load everything into seperate modules to keep the main file clean and easier to manage the housekeeping. I’d be keen to see this area develop further if there is better practices or ways to build out. 

 

In er4 I used a function to give a title block a differing colour to break the rules apart but even at 50odd rules and users comments I had saved for reference the main file was a bit of a mess. 

So moving to er5 is like a clean start. 

 

I noticed today though in er4 that I only had to have the home table in the main file but in er5 the home table has to be loaded in each module  or the devices have no reference. 

 

I have a few systems out in customers homes that are running er4 so keen to get this right to implement elsewhere later. 
 

Thanks for the ER framework and continual development. 

Posted

Please login or register to see this code.

I do this to devide my main in chapters for easy acces andyou see it whenQA start

  • Like 1
Posted
10 minutes ago, Sjakie said:

Please login or register to see this code.

I do this to devide my main in chapters for easy acces andyou see it whenQA start

@Sjakie May i ask you, what is the syntax of using # infront of letter C..What is this rule logging to you in general?

Posted (edited)

Please login or register to see this code.

As menthioned earlier between ------------- is chapter

# in front need for different colors in debug

I have different colors for mostly bright for on, true, safe,   and abit dark for the oposite

GV set pink

$$QAgv  violet

light on and of is also different

Easy to read the debug if you need to see what is happening

 

Edited by Sjakie
add
  • Topic Author
  • Posted (edited)
    42 minutes ago, Pica2017 said:

    have been short on time so only had a play with er5 until now but today I made the switch at home . I don’t have hundreds of rules or not doing anything complex but also thought to load everything into seperate modules to keep the main file clean and easier to manage the housekeeping. I’d be keen to see this area develop further if there is better practices or ways to build out. 

     

    In er4 I used a function to give a title block a differing colour to break the rules apart but even at 50odd rules and users comments I had saved for reference the main file was a bit of a mess. 

    So moving to er5 is like a clean start. 

     

    I noticed today though in er4 that I only had to have the home table in the main file but in er5 the home table has to be loaded in each module  or the devices have no reference. 

     

    I have a few systems out in customers homes that are running er4 so keen to get this right to implement elsewhere later. 
     

    Thanks for the ER framework and continual development. 

    Well, the home table only needs to be loaded in the module that is first loaded.

    If your QuickApp:main(er) has prio 0 and all other modules prio > 0 then it is enough to load in main.

     

    Otherwise, have an "init module" with a very high priority like -100 (I know, the prio is backwards)

    and do all the initialisation there - like setting up the home table.

    Edited by jgab
    • Thanks 1
    Posted (edited)

    Hi Jan

     

    How do i migrate these rules to ev5 ?

    my "alarm / will arm" is now tryArm ?

     

    Please login or register to see this code.

     

     

    Edited by ChristianSogaard
    Typo
  • Topic Author
  • Posted

    Yes, it's tryArm like in this post

     

    The problem is that in the past, when we armed a partition using the HC3 Web UI or the Yubii app, there were info that the partition was being armed and counting down. Unfortunately, that is removed in the later firmwares.

     

    What Fibaro did was that they introduced the tryArm api that returns the partitions that have devices that are breached - so we could notify the user and maybe unarm the partition. That is what :tryArm uses. You get an event back with the devices that are breached, if any.

     

    If we arm partitions with R5 rules we should use :tryArm...

    The problem is of course if the user arms a partition with the Yubii app or web UI, because then we are not getting any event we can trigger on - until it's too late.

     

    So, I have created a simple QuickApp with buttons to arm and disarm that sends events to ER5 to run a tryArm rule to arm the partition - and I'm not using the HC3 alarm web UI or the Yubii app to arm... Maybe in the future they will give us back a notification that something are about to be armed.

    Posted
    7 minutes ago, jgab said:

    Yes, it's tryArm like in this post

     

    The problem is that in the past, when we armed a partition using the HC3 Web UI or the Yubii app, there were info that the partition was being armed and counting down. Unfortunately, that is removed in the later firmwares.

     

    What Fibaro did was that they introduced the tryArm api that returns the partitions that have devices that are breached - so we could notify the user and maybe unarm the partition. That is what :tryArm uses. You get an event back with the devices that are breached, if any.

     

    If we arm partitions with R5 rules we should use :tryArm...

    The problem is of course if the user arms a partition with the Yubii app or web UI, because then we are not getting any event we can trigger on - until it's too late.

     

    So, I have created a simple QuickApp with buttons to arm and disarm that sends events to ER5 to run a tryArm rule to arm the partition - and I'm not using the HC3 alarm web UI or the Yubii app to arm... Maybe in the future they will give us back a notification that something are about to be armed.

    Thank you jan for your detailed explanation

    Would you mind share the Alarm QuickApp you mentioned?

    Posted

    Jan??

    It's working in scene but nothing happends in ER5 not eve debug!

    Please login or register to see this code.

     

    Posted (edited)
    40 minutes ago, Sjakie said:

    Jan??

    It's working in scene but nothing happends in ER5 not eve debug!

    Please login or register to see this code.

     

    i copied your rule and changed the ID - works for me

    rule("951:key == '4:Pressed' => print(env.event); log('Key %s',951:key)")
     

    Please login or register to see this code.

    did you add the 

    Please login or register to see this code.

     

    Edited by ChristianSogaard
    Typo
    • Like 1
    Posted

    yes I did but I copied my rule in TESTQA (and  offcourse I forgot to copy it there too)

    Thanks for remebering me!

    Posted (edited)

    When using tryArm like this

    Please login or register to see this code.

    seems to work fine -ALARM cancel the arming if a windows is opened.

    But next step is post a message, which windows is opened. and i was expecting that below rule would give me that,.

    from the log, it seems that it newer triggers ?

     

     

    Please login or register to see this code.

     

     

     

    Edited by ChristianSogaard
    Typo
  • Topic Author
  • Posted
    1 hour ago, ChristianSogaard said:

    When using tryArm like this

    Please login or register to see this code.

    seems to work fine -ALARM cancel the arming if a windows is opened.

    But next step is post a message, which windows is opened. and i was expecting that below rule would give me that,.

    from the log, it seems that it newer triggers ?

     

     

    Please login or register to see this code.

     

     

     

     

    well, it works well for me - both for whole house and individual partitions.

    Have you tried open a window before you arm? :-) 

    You won't get any event if there are no breached devices in any armed partition.

    Posted (edited)

    I am sharing here a little QA that creates the HT table content used in ER4 or ER5 for you according to your system. Spares a lot of coding.

    It auto detects space characters in the name of the device and replaces it by _ character.

    Also it removes any starting spaces. It doesn't take into account devices that have numbers as starting letters in their names. (there are a lot of endpoints that I never renamed, so it just aviods them) 

    The HT table is created in alphabetical order.

    You can select if only visible devices are you interested in, and there are two buttons for zwave and zigbee devices accordingly.

    For me it is a big help, if i have a system with hundreds of devices, i don't need to manually set up my HT table.

    It separates devices into starting letter categories too.

    Just press one of the print buttons and you can copy past your entire device table from debug window into your HT table in ER5 or ER4.

    Maybe somone will find this helpfull.

     

    Please login or register to see this attachment.

     

     

     

    Please login or register to see this attachment.

    Edited by Neo Andersson
    • Like 3
    • Thanks 2
    Posted (edited)
    On 11/17/2023 at 7:23 AM, jgab said:

    Http and Nodered
     

    HTTP

    http requests are done with

    Please login or register to see this code.

    They are synchronous, meaning that the call returns the result. More specifically, the json.decoded result.data field of the response.

     

    options can be 

    opts.type, the header content-type.

    opts.user, user name for credentials

    opts.pwd, password for credentials

    opts.timeout, request timeout

     

    Ex.

    Please login or register to see this code.

    Here http.get returns a complex json table and we access the .datetime field.

     

    In practice, the request could fail for various reasons and if we do a http.get(...).datetime we would get a rule error as the http.get returns nil.

    To guard agains an error and nil value returned, we could do

    Please login or register to see this code.

    Here we assign the result to a variable 'res' and if true (not nil) we access res.datetime, else we return 'no time' to the log function.

     

    Nodered

     

    To call nodered we have 

    Please login or register to see this code.

    and we need to have setup the ER variable noderedURL first.

    Ex.

    Please login or register to see this code.

     

    The nr.* functions return the response from the nodered flow we are calling.

     

    There are 2 types of NR flows we can integrate with, named sync and async.

    The 'sync' means that the flow called ends with an "http response" node.

    In some cases that is not an optimal way to design the flow and we can then do an

    'async' flow, which means that we need to call the outgoing event flow ourself when the result should be returned.

     

    The communication between NR and ER is with events, json structs with a type key, like the events we deal with in ER.

    The incoming msg.payload is the event, and we construct a new msg.payload event when we return the result to the HC3.

     

    In nodered we have a flow with an incoming http endpoint http://<IP>:<PORT>/ER_HC3

     

    Please login or register to see this attachment.

    Please login or register to see this spoiler.

     

    How to send the post from above with ER?

     

    rule("noderedURL='http://192.168.100.178:1880'") 

     

    now where do a put my "/CAST" string, and where do i send the data ( in my case the "requestStringToJSON"?)

     

     

    Edited by Neo Andersson

    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...