IHC and Home Assistant failover / Heartbeat using node-red

Hi

My setup: IHC controller with push buttons around the house and output modules for lamp spots.
Normally my IHC is used primarely for input button push and my lamp spots are always on. In each lamp is a zigbee/hue bulp that I turn on from HA.

Now what happens if HA breaks down?

Up untill now I’ve had a program on each output to toggle the lamp output if I press and hold my button for 10 seconds.
But if theres a breakdown, I would like the 10 seconds to be only 1 second.

First off I made a program on the IHC that would listen for a switch to change and if so, reset a 2 minute timer. (HeartbeatSignal)
If the timer is running and I long press my button, I count down 10 seconds before I toggle my output.
If the timer is 0 (stoppet), I only count 1 minute before I toggle my output.
If the 2 minute timer is 0 I turn on another switch for use as error signal.
Remember that you can add a switch in IHC and use a dataline where theres no module on, that way you create a “virtual” transferable variable.

Idea is that HA each minute toggle my heartbeat signal, thus keeping my 2 minute timer running all day.

Picture time, and I’m sorry it’s in Danish. If anyone ever use this guide and need translations please contact me.

First my 2 switch for signal transferring
image

As you see I use dataline 16:7+8
image

Heres how my program looks from the overview
Button press
Heartbeat signal
Output
Error signal
Short push timer
Long pust timer
Heartbeat signal timeout
image

Inside function block

Restarting timeout counter
image

Turning error signal on
image

Activate timer for long push if button is pressed and timeout is counting else start counting on short timer.
image

If button is released at any time reset it all
image

And a long one:
If any of the push counters reach 0, do some magic.
If heartbeat is 0 and we dont get a signal, toggle output and reset timer
If timeoput counting toggle output and reset timer

On powerup start timeout count down in case HA and IHC was down at the same time
image

If you create following code in heartbeat.ifb in folder C:\Program Files (x86)\LK IHC Control\IHC Visual\FunctionBlocks
then you can add the code from mouse menu in IHC

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE functionblock [
   <!ELEMENT functionblock ANY>
   <!ATTLIST functionblock id ID #REQUIRED
                  name CDATA ""
                  master_schneider_electric (yes | no) "no"
                  master_type CDATA ""
                  master_version CDATA ""
                  master_name CDATA ""
                  master_programmer CDATA ""
                  master_date_year CDATA "0"
                  master_date_month CDATA "0"
                  master_date_day CDATA "0"
                  locked (yes | no) "no"
                  icon CDATA "_0x0"
                  note CDATA ""
                  helpfile CDATA ""
                  udf CDATA "">
   <!ELEMENT inputs ANY>
   <!ATTLIST inputs id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT resource_input ANY>
   <!ATTLIST resource_input id ID #REQUIRED
                  name CDATA ""
                  backup (yes | no) "no"
                  icon CDATA "_0x0"
                  note CDATA ""
                  inivalue (on | off) "off"
                  accessibility (read | write | read-write) "read-write"
                  note-2 CDATA ""
                  udf CDATA "">
   <!ELEMENT outputs ANY>
   <!ATTLIST outputs id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT resource_output ANY>
   <!ATTLIST resource_output id ID #REQUIRED
                  name CDATA ""
                  backup (yes | no) "no"
                  icon CDATA "_0x0"
                  note CDATA ""
                  inivalue (on | off) "off"
                  accessibility (read | write | read-write) "read-write"
                  note-2 CDATA ""
                  udf CDATA "">
   <!ELEMENT settings ANY>
   <!ATTLIST settings id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT resource_timer ANY>
   <!ATTLIST resource_timer id ID #REQUIRED
                  name CDATA ""
                  backup (yes | no) "no"
                  icon CDATA "_0x0"
                  note CDATA ""
                  hour CDATA #REQUIRED
                  minute CDATA #REQUIRED
                  second CDATA #REQUIRED
                  millisecond CDATA #REQUIRED
                  note-2 CDATA ""
                  udf CDATA "">
   <!ELEMENT internalsettings ANY>
   <!ATTLIST internalsettings id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT programs ANY>
   <!ATTLIST programs id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT program_simple ANY>
   <!ATTLIST program_simple id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT events ANY>
   <!ATTLIST events id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT event ANY>
   <!ATTLIST event id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  link1 IDREF #IMPLIED
                  link2 IDREF #IMPLIED
                  method CDATA "_0x0"
                  udf CDATA "">
   <!ELEMENT actions ANY>
   <!ATTLIST actions id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  type CDATA "_0x0"
                  udf CDATA "">
   <!ELEMENT action ANY>
   <!ATTLIST action id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  link1 IDREF #IMPLIED
                  link2 IDREF #IMPLIED
                  method CDATA "_0x0"
                  udf CDATA "">
   <!ELEMENT program_sub ANY>
   <!ATTLIST program_sub id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  udf CDATA "">
   <!ELEMENT conditions ANY>
   <!ATTLIST conditions id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  type (and | or) "and"
                  udf CDATA "">
   <!ELEMENT condition ANY>
   <!ATTLIST condition id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  link1 IDREF #IMPLIED
                  link2 IDREF #IMPLIED
                  method CDATA "_0x0"
                  udf CDATA "">
   <!ELEMENT event_power ANY>
   <!ATTLIST event_power id ID #REQUIRED
                  name CDATA ""
                  icon CDATA "_0x0"
                  note CDATA ""
                  type (up | down) "up"
                  udf CDATA "">
]>
<functionblock id="_0x27b028" name="Lang tryk kip med Heartbeat" master_name="Lang tryk kip med Heartbeat" master_programmer="MikaelKristensen" master_date_year="2021" master_date_month="1" master_date_day="19" locked="yes" icon="_0x10">
      <inputs id="_0x27b123" name="Input" icon="_0x4" note="Variablene i denne gruppering er input til funktionsblokken">
         <resource_input id="_0x27d011" name="Tryk" icon="_0x36"/>
         <resource_input id="_0x27b211" name="Heartbeat" icon="_0x36"/>
      </inputs>
      <outputs id="_0x27b324" name="Output" icon="_0x14" note="Variablene i denne gruppering er output fra funktionsblokken">
         <resource_output id="_0x27b412" name="LysUdgang" icon="_0x39"/>
         <resource_output id="_0x27d812" name="FejlSignal" icon="_0x39"/>
      </outputs>
      <settings id="_0x27b525" name="Indstillinger" icon="_0xd" note="Variablene i denne gruppering er indstillinger til funktionsblokken">
         <resource_timer id="_0x27b610" name="TrykTidKort" icon="_0x43" hour="0" minute="0" second="1" millisecond="0"/>
         <resource_timer id="_0x27d110" name="TrykTidLang" icon="_0x43" hour="0" minute="0" second="10" millisecond="0"/>
         <resource_timer id="_0x27d210" name="HeartBeatTimeout" icon="_0x43" hour="0" minute="2" second="0" millisecond="0"/>
      </settings>
      <internalsettings id="_0x27b729" name="Interne variable" icon="_0x13" note="Variablene i denne gruppe er private variable til funktionsblokken"/>
      <programs id="_0x27b826" name="Programmer" icon="_0x19" note="Gruppering af funktionblokkens programmer">
         <program_simple id="_0x27d31e" name="Genstart Heartbeat" icon="_0x7">
            <events id="_0x27d464" name="Hændelser" icon="_0xb" note="Hændelser som starter program">
               <event id="_0x27d6c8" name="%P bliver ændret" icon="_0xc" note="Start program når %P skifter værdi" link1="_0x27b211" method="_0x96"/>
            </events>
            <actions id="_0x27d566" name="Kommandoer" icon="_0x8" note="Gruppering af kommandoer som udføres når hændelse er indtruffet" type="_0x2">
               <action id="_0x27d7ca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27d210" method="_0x19"/>
               <action id="_0x2869ca" name="Aktiver nedtælling på %P" icon="_0x9" note="Aktiver nedtælling på %P" link1="_0x27d210" method="_0xd2"/>
               <action id="_0x27deca" name="%P = OFF" icon="_0x9" note="Sætter %P til OFF" link1="_0x27d812" method="_0x14"/>
            </actions>
         </program_simple>
         <program_simple id="_0x27d91e" name="FejlSignalAktivering" icon="_0x7">
            <events id="_0x27da64" name="Hændelser" icon="_0xb" note="Hændelser som starter program">
               <event id="_0x27dcc8" name="%P -&gt; 0" icon="_0xc" note="Start program når %P skifter til 0" link1="_0x27d210" method="_0xa"/>
            </events>
            <actions id="_0x27db66" name="Kommandoer" icon="_0x8" note="Gruppering af kommandoer som udføres når hændelse er indtruffet" type="_0x2">
               <action id="_0x27ddca" name="%P = ON" icon="_0x9" note="Sætter %P til ON" link1="_0x27d812" method="_0xa"/>
            </actions>
         </program_simple>
         <program_simple id="_0x27df1e" name="Start Timer for lang tryk" icon="_0x7">
            <events id="_0x27e064" name="Hændelser" icon="_0xb" note="Hændelser som starter program">
               <event id="_0x27e2c8" name="%P -&gt; ON" icon="_0xc" note="Start program når %P skifter til ON" link1="_0x27d011" method="_0xa"/>
            </events>
            <actions id="_0x27e166" name="Kommandoer" icon="_0x8" note="Gruppering af kommandoer som udføres når hændelse er indtruffet" type="_0x2">
               <program_sub id="_0x27e31f" name="Under program" icon="_0x7">
                  <conditions id="_0x27e465" name="Betingelser" icon="_0x16" note="Gruppering af betingelser til logisk test">
                     <condition id="_0x27e7c9" name="%P tæller ned" icon="_0x1a" note="Betingelse at %P er aktiveret til at tælle ned" link1="_0x27d210" method="_0xd2"/>
                  </conditions>
                  <actions id="_0x27e566" name="Kommandoer ved betingelser sande" icon="_0x8" note="Gruppering af kommandoer som udføres når betingelser er sande" type="_0x1">
                     <action id="_0x28caca" name="Aktiver nedtælling på %P" icon="_0x9" note="Aktiver nedtælling på %P" link1="_0x27d110" method="_0xd2"/>
                  </actions>
                  <actions id="_0x27e666" name="Kommandoer ved betingelser falske" icon="_0x8" note="Gruppering af kommandoer som udføres når betingelser er falske">
                     <action id="_0x28cbca" name="Aktiver nedtælling på %P" icon="_0x9" note="Aktiver nedtælling på %P" link1="_0x27b610" method="_0xd2"/>
                  </actions>
               </program_sub>
            </actions>
         </program_simple>
         <program_simple id="_0x27ea1e" name="Stop timer for lang tryk" icon="_0x7">
            <events id="_0x27eb64" name="Hændelser" icon="_0xb" note="Hændelser som starter program">
               <event id="_0x27edc8" name="%P -&gt; OFF" icon="_0xc" note="Start program når %P skifter til OFF" link1="_0x27d011" method="_0x14"/>
            </events>
            <actions id="_0x27ec66" name="Kommandoer" icon="_0x8" note="Gruppering af kommandoer som udføres når hændelse er indtruffet" type="_0x2">
               <action id="_0x27eeca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27b610" method="_0xdc"/>
               <action id="_0x27efca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27b610" method="_0x19"/>
               <action id="_0x27f0ca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27d110" method="_0xdc"/>
               <action id="_0x27f1ca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27d110" method="_0x19"/>
            </actions>
         </program_simple>
         <program_simple id="_0x27f21e" name="Toggle udgang" icon="_0x7">
            <events id="_0x27f364" name="Hændelser" icon="_0xb" note="Hændelser som starter program">
               <event id="_0x27f5c8" name="%P -&gt; 0" icon="_0xc" note="Start program når %P skifter til 0" link1="_0x27b610" method="_0xa"/>
               <event id="_0x2803c8" name="%P -&gt; 0" icon="_0xc" note="Start program når %P skifter til 0" link1="_0x27d110" method="_0xa"/>
            </events>
            <actions id="_0x27f466" name="Kommandoer" icon="_0x8" note="Gruppering af kommandoer som udføres når hændelse er indtruffet" type="_0x2">
               <program_sub id="_0x27f61f" name="Hvis HeartBeat mangler" icon="_0x7">
                  <conditions id="_0x27f765" name="Betingelser" icon="_0x16" note="Gruppering af betingelser til logisk test">
                     <condition id="_0x27fbc9" name="%P = 0" icon="_0x1a" note="Betingelse at %P er 0" link1="_0x27d210" method="_0xa"/>
                     <condition id="_0x2808c9" name="%P = ON" icon="_0x1a" note="Betingelse at %P er ON" link1="_0x27d011" method="_0xa"/>
                  </conditions>
                  <actions id="_0x27f866" name="Kommandoer ved betingelser sande" icon="_0x8" note="Gruppering af kommandoer som udføres når betingelser er sande" type="_0x1">
                     <action id="_0x27fcca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27b610" method="_0xdc"/>
                     <action id="_0x27fdca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27b610" method="_0x19"/>
                     <action id="_0x27feca" name="Kip %P" icon="_0x9" note="Sætter %P til modsat værdi af aktuel værdi" link1="_0x27b412" method="_0x23"/>
                  </actions>
                  <actions id="_0x27f966" name="Kommandoer ved betingelser falske" icon="_0x8" note="Gruppering af kommandoer som udføres når betingelser er falske">
                     <action id="_0x280cca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27b610" method="_0xdc"/>
                     <action id="_0x280dca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27d110" method="_0xdc"/>
                     <action id="_0x280eca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27b610" method="_0x19"/>
                     <action id="_0x2810ca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27d110" method="_0x19"/>
                  </actions>
               </program_sub>
               <program_sub id="_0x27ff1f" name="Hvis HeartBeat signal er OK" icon="_0x7">
                  <conditions id="_0x280065" name="Betingelser" icon="_0x16" note="Gruppering af betingelser til logisk test">
                     <condition id="_0x2804c9" name="%P tæller ned" icon="_0x1a" note="Betingelse at %P er aktiveret til at tælle ned" link1="_0x27d210" method="_0xd2"/>
                     <condition id="_0x2809c9" name="%P = ON" icon="_0x1a" note="Betingelse at %P er ON" link1="_0x27d011" method="_0xa"/>
                  </conditions>
                  <actions id="_0x280166" name="Kommandoer ved betingelser sande" icon="_0x8" note="Gruppering af kommandoer som udføres når betingelser er sande" type="_0x1">
                     <action id="_0x2805ca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27d110" method="_0xdc"/>
                     <action id="_0x2806ca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27d110" method="_0x19"/>
                     <action id="_0x2807ca" name="Kip %P" icon="_0x9" note="Sætter %P til modsat værdi af aktuel værdi" link1="_0x27b412" method="_0x23"/>
                  </actions>
                  <actions id="_0x280266" name="Kommandoer ved betingelser falske" icon="_0x8" note="Gruppering af kommandoer som udføres når betingelser er falske">
                     <action id="_0x280aca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27b610" method="_0xdc"/>
                     <action id="_0x280bca" name="Stands tælling på %P" icon="_0x9" note="Standser evt. igangværende optælling eller nedtælling på %P" link1="_0x27d110" method="_0xdc"/>
                     <action id="_0x280fca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27b610" method="_0x19"/>
                     <action id="_0x2811ca" name="%P = Initialværdi" icon="_0x9" note="Sætter %P til dens initialværdi" link1="_0x27d110" method="_0x19"/>
                  </actions>
               </program_sub>
            </actions>
         </program_simple>
         <program_simple id="_0x28641e" name="PowerUp Start nedtælling" icon="_0x7">
            <events id="_0x286564" name="Hændelser" icon="_0xb" note="Hændelser som starter program">
               <event_power id="_0x2867c8" name="Powerup" icon="_0xc" note="Start program ved Powerup"/>
            </events>
            <actions id="_0x286666" name="Kommandoer" icon="_0x8" note="Gruppering af kommandoer som udføres når hændelse er indtruffet" type="_0x2">
               <action id="_0x2868ca" name="Aktiver nedtælling på %P med initial værdi" icon="_0x9" note="Aktiver nedtælling på %P med initial værdi" link1="_0x27d210" method="_0xbe"/>
               <action id="_0x286aca" name="%P = OFF" icon="_0x9" note="Sætter %P til OFF" link1="_0x27d812" method="_0x14"/>
            </actions>
         </program_simple>
      </programs>
</functionblock>


Adding switches to configuration manually.
Remeber that you have to open your IHC save file and take the hex number and convert to decimals to get the correct ID’s
See integration manual for IHC.

ihc:
  - url: 'http://192.168.1.10:81'
    username: ''
    password: ''
    info: true
    auto_setup: true
    switch:
        # HeartBeat Fejlsignal
      - id: 2670683 # 28c05b
        name: 'HeartBeat'
        #type: 
        note: 'HeartBeat'
        position: 'HeartBeat'
        # HeartBeat Signal
      - id: 2669915 # 28bd5b
        name: 'HeartBeatError'
        #type: 
        note: 'HeartBeatError'
        position: 'HeartBeatError'

Gets the switches added to HA

Using it in node red as follow

[{"id":"6eaee76f.299588","type":"bigtimer","z":"b7656499.b2541","outtopic":"","outpayload1":"","outpayload2":"","name":"Output every minute all day","comment":"","lat":"57.0011102","lon":"9.7323398","starttime":"0","endtime":"1425","starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"","outtext2":"","timeout":"10","sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":140,"y":400,"wires":[[],["36c8e486.686a0c","3d070dc0.e415d2","4bc75279.16308c","ab7fecbe.264c","cc66c49.756b038","720940bb.7f248"],[]]},{"id":"720940bb.7f248","type":"api-call-service","z":"b7656499.b2541","name":"HeartBeat","server":"ee78531f.18514","version":1,"debugenabled":false,"service_domain":"switch","service":"toggle","entityId":"switch.heartbeat","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":520,"y":380,"wires":[[]]},{"id":"ee78531f.18514","type":"server","name":"Home Assistant Main","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":true}]

The error signal could be bound for a telephone warning that something is wrong.

If anyone has ideas please share :slight_smile:

1 Like