Scripted HAPCAN configuration

HAPCAN installation tips and troubleshooting when assembling, commissioning and configuring devices.
Rozwiązywanie problemów z instalacją HAPCAN, budową, uruchamianiem i konfiguracją urządzeń.
Post Reply
Jacek
Posts: 559
Joined: 17 Feb 2007, 18:00

Scripted HAPCAN configuration

Post by Jacek »

It might be interesting for someone who wants to programme in perl.
https://github.com/asicdruide/hapconf
Thank you Klaus for this.
The concept i have in mind really allows to switch the configuration of
my eval board completely within <30sec of flash-time.
Usually the script is changed within minutes for new tests like one
button enabling/disabling boxes dynamically, playing with timers, ...

It really makes fun to play around with the modules.

Currently supported are the ethernet module (partly), the back box
button module (fully) and the relay module (fully).
Next steps will be the rgb_led module and the ir module.
Regards
Jacek
asicdruide
Posts: 13
Joined: 30 Jun 2014, 09:44
Location: Germany

Re: Scripted HAPCAN configuration

Post by asicdruide »

Jacek is right, this configuration software is written in perl. To just use it, you don't see much perl.
Have a look at the examples, e.g. https://github.com/asicdruide/hapconf/b ... er.hapconf

The big advantage of the script based approach is that the tool handles many details for you.

Once you gave ports names you're able to refer them symbolically. If you want to change e.g. afterwards
the assignment of buttons to relays you just change the port-name-assignment and the change propagates
automagically to where ever it's needed, namely all relay boxes that reacted on the former ports.

Or, imagine you use an advanced setup with groups of boxes enabled/disabled by messages and
want to add a box to one of the enable/disable box_groups. How do you insert a box between
already existing ones? Script based it's copy-paste a line where is should go, flash it and you're done.
The tool adds the details about where box_groups start and end for you.

Have fun.
asicdruide
Posts: 13
Joined: 30 Jun 2014, 09:44
Location: Germany

Re: Scripted HAPCAN configuration

Post by asicdruide »

...some more examples what you can do with HAPCAN modules.

* two buttons to step thru light scenes distributed over modules (relay , dimmer)
* one message triggering different delayed actions
* pathological example (commented ut in the code) where two modules trigger each other mit max rate

Have fun,

Klaus
djsuszi
Posts: 57
Joined: 14 Sep 2015, 11:03

Re: Scripted HAPCAN configuration

Post by djsuszi »

asicdruide wrote:Klaus
Can you give more example, I try to figure it out and I have problems :)
Maybe you have your own configuration for your script ?
I would like to use your hapconf to program my new installation.

for examples
https://github.com/asicdruide/hapconf/b ... p3.hapconf

Code: Select all

button_back_box13        ("bbb")
<<<< it's name of module which I will see in HapCan Programer ?

Code: Select all

  ->port_name            ( 1   , "B1" )
...
  ->port_name            (13   , "B13")
we have button with ports, it should me 0 or 14?

Code: Select all

  ->message              ("4up"                  , "c"     , "B7" )
  ->message              ("5up"                  , "c"     , "B8" )
  ->message              ("6up"                  , "c"     , "B9" )
  ->message              ("7up"                  , "c"     , "B10")
  ->message              ("7down"                , "o"     , "B10")
"o" is open, "c" is close ? but buttons have much more states.
http://hapcan.com/devices/universal/uni ... v_3-1-3-x/
"7 types of button behaving is recognized: button pressed, released,
pressed for 400ms, pressed for 4s, released within 400ms, released
between 400ms and 4s, released after 4s"

Code: Select all

  ->thermostat_threshold (22.0)
  ->thermostat_hysteresis( 1.0)
  ->temperature_offset   ( 0.0)
how to disable thermostat, and set sending temperature in 5 min loop ?

what is this bellow ?

Code: Select all

  ->message              ("light2->on"           , "->on"  , "K2")
  ->message              ("light2->off"          , "->off" , "K2")
  ->message              ("light5->on"           , "->on"  , "K5")
  ->message              ("light5->off"          , "->off" , "K5")
  ->message              ("light6->on"           , "->on"  , "K6")
  ->message              ("light6->off"          , "->off" , "K6")
  

Code: Select all

 ->box                  ("enabled" , "toggle"   ,        "K2"                , "5up"  )
  ->box                  ("enabled" , "toggle"   ,        "K4"                , "7up"  )
  ->box                  ("enabled" , "toggle"   ,        "K4"                , "7down")
as I understood, when Button_nr8 is closed, It should toogle K2 ?
when I press button_nr_7 is should toogle (for example ring bell) K4, and when I release it, it will stop ringing ?
asicdruide
Posts: 13
Joined: 30 Jun 2014, 09:44
Location: Germany

Re: Scripted HAPCAN configuration

Post by asicdruide »

Hello djsuszi,

i'll try to explain the structure of a configuration spript.

The setup i used was a 13-button backbox module, a relay, module, a ir-module and a LED dimmer module.

One configuration consists of several parts.
Part 1 defines all modules which should be part of the configuration (together with node-specific settings like ID, url, symbolic name, ...).
Part 2 defines messages to be send around (defined together with the sender and the condition when they should be send and a symbolic name).
Part 3 defines the actions to be done (defined together with the acting module and the action based on the defined messages).



>Can you give more example, I try to figure it out and I have problems :)
>Maybe you have your own configuration for your script ?
>I would like to use your hapconf to program my new installation.

>for examples
>https://github.com/asicdruide/hapconf/b ... p3.hapconf

The example you're referring to is a quite old one.
In the beginning i've changed the syntax quite often until i found readability ok.
Please use a newer example (e.g. eval_board.hapconf) as reference.



>button_back_box13 ("bbb") <<<< it's name of module which I will see in HapCan Programer ?
Yes it is. It's written to address 0xF00030 of EEPROM.

> ->port_name ( 1 , "B1" )
>...
> ->port_name (13 , "B13")
>we have button with ports, it should me 0 or 14?

Sorry didn't got your question.
This statment assigns a symbolic name ('B13' in the above example) to port number 13.
The symbolic name should usually be more describing where the port is connected to
like bath.sw1 or living.presence.
The legal port numbers are depending on the version of the module.
The appropriate number is populated in lines 150..168 of button.pm.
Whenever you want to refer to a port you might use the symbolic name.
This allows remapping to another module/port without having to change each reference
and code readability is better, too.


> ->message ("4up" , "c" , "B7" )
> ->message ("5up" , "c" , "B8" )
> ->message ("6up" , "c" , "B9" )
> ->message ("7up" , "c" , "B10")
> ->message ("7down" , "o" , "B10")
>
>"o" is open, "c" is close ? but buttons have much more states.
>http://hapcan.com/devices/universal/uni ... v_3-1-3-x/
>"7 types of button behaving is recognized: button pressed, released,
>pressed for 400ms, pressed for 4s, released within 400ms, released
>between 400ms and 4s, released after 4s"

This section assign symbolically named events (e.g. '4up' in the above example)
to a condition that trigger them.
All possible event triggers are summarized in lines 70..106 of button.pm.
You might change the existing ones or add you own ones.
The event name must be unique, the implementation (the byte array) does not need
to be unique.
E.g. the line
,":click" => [0xFC , undef , 0x10]
adds the event ':click' to the allowed ones having the same effect as ':co'.

The three groups describe the different situations, please see comment there.
Please note that different messages are sent depending on state of LED.
If you care about LED state, use the ':0c' or ':1c' event, if you don't care
about the LED state, use ':c' event.






> ->thermostat_threshold (22.0)
> ->thermostat_hysteresis( 1.0)
> ->temperature_offset ( 0.0)
>how to disable thermostat, and set sending temperature in 5 min loop ?

I'm not sure whether i've implemented thermostat messages completely.
To block sending temp messages you might set threshold to low value.
If you don't want them don't declare temp messages.



>what is this bellow ?
> ->message ("light2->on" , "->on" , "K2")
> ->message ("light2->off" , "->off" , "K2")
> ->message ("light5->on" , "->on" , "K5")
> ->message ("light5->off" , "->off" , "K5")
> ->message ("light6->on" , "->on" , "K6")
> ->message ("light6->off" , "->off" , "K6")

The relaymodule can sent messages when a relay is switched (as confimation
of action). The above declares those messages.
If you don't want them, don't declare them.



> ->box ("enabled" , "toggle" , "K2" , "5up" )
> ->box ("enabled" , "toggle" , "K4" , "7up" )
> ->box ("enabled" , "toggle" , "K4" , "7down")

>as I understood, when Button_nr8 is closed, It should toogle K2 ?
Yes, that's right.

>when I press button_nr_7 is should toogle (for example ring bell) K4, and when I release it, it will stop ringing ?
Yes except that the 7up and 7down messages are sent from port10 of button module.


I hope this helps understanding the concept.
In the next months i'll order my complete configuration (as building our
appartment approaches completion). I'll pick up development of hapconf than.

Best regards,
Klaus
djsuszi
Posts: 57
Joined: 14 Sep 2015, 11:03

Re: Scripted HAPCAN configuration

Post by djsuszi »

asicdruide wrote: In the next months i'll order my complete configuration (as building our
appartment approaches completion). I'll pick up development of hapconf than.
are you ready for this big step ? :)


Best regards,
Piotr
Post Reply