HomeAssistant INIM API Notes Public-V5
HomeAssistant INIM API Notes Public-V5
This document contains my findings on accessing the INIM alarm panel through local internet by
using Home Assistant’s http request functionality. I used Wireshark with the filter set to “ip.addr ==
192.168.1.92”, the local address of my INIM alarm panel. I tested the commands and checked their
json output with Postman. The findings basically mimick the functionality of the panel’s local
webserver, when a SmartLAN-G board is present. My panel’s webserver address is
192.168.1.92:5050. There is an installation manual to set up the two versions of this board
SmartLAN-G and SmartLAN-SI. I own the G version and have therefore not experimented with the SI
board. The documentation says the SI board does not have a local webserver.
The command for executing an arming scenario is “do_sce”, followed by the additional parameter
“par” for the relevant scenario (I have five arming scenarios):
1
For the front-end I created a picture elements card with
the relevant tap actions. Key is adding the script as an
entity so that on and off states in state_image can be
used. I created two different PNG images for the button
in ON and OFF state. When the button is pressed, the
image briefly changes colour.
To find out which alarm scenario is currently set, I use the following parameters:
I used this response to create 5 binary_sensors in NodeRed with the on/off status of each alarm
scenario. I ensured that if one status goes “on” the others are set to “off”. Depending on the
required response speed you can update these sensors every 10 – 60 secs or so.
With scenarios to turn on and off and sensors for current state of each snenario done, we can now
create template switches for setting and reading the alarm scenario’s in Home Assistant as follows:
2
created two outputs which connect to a relay disconnecting the power of the SmartLAN-G board (5
secs) and the power to my OpenSprinkler system. In both cases to resolve their regular LAN/wifi
disconnection issues.
I have five outputs defined, that when “on” perform the following functions:
• “Siren sounding” Alarm is tiggered, alarm is ringing
• “Blinking” One of the alarm arming scenarios is on
• “Flashing” Silent alarm indicating panel faults and errors
• “LAN” interrupt” Output interrupting INIM internal LAN pwr supply for a 5 sec reset
• “OpenSprinkler reset” Output interrupting OpenSpinkler pwr supply for a 5 sec reset
To get the output state for each of the “commands” I used “mod=cmd” as parameter for the restful
request:
mod Action
cmd Command status
st=status: 0=off, 1= on
mod=part
3
The json response for partition states is:
{"part": [
{"lb": "Keuken (60 sec) ", "am": "4", "st": "1", "mm": "0", "id": "0"},
{"lb": "Kelder/beg grond", "am": "4", "st": "1", "mm": "0", "id": "1"},
{"lb": "Studeerkamers ", "am": "4", "st": "1", "mm": "0", "id": "2"},
{"lb": "Ouder slaapkmr ", "am": "4", "st": "1", "mm": "0", "id": "3"},
{"lb": "24 uurs zone ", "am": "4", "st": "1", "mm": "0", "id": "4"}]}
Normally changing the partition arming state is done by executing arming scenario’s. But if you
would like to set individual partitions, for instance to run tests, do so as follows:
A reset is necessary to remove the alarm status from the partitions and zones when an alarm has
been triggered.
mod=zone
4
The json response is:
{"zone": [
{"lb": "Keuken ","st": "1","mm": "0","by": "1","id": "0"},
{"lb": "Kelder voor ","st": "1","mm": "0","by": "1","id": "1"},
……
{"lb": "Waterpomp ","st": "1","mm": "0","by": "1","id": "14"}]}
Enabling/disabling a zone
mod=do_zone
Issues executing http request calls for INIM states from NodeRed
I found it easiest to execute http request calls from NodeRed. This is because when responses
contain a large amount of data, in NodeRed it is easy to navigate to the data one is interested in,
much easier than doing this in Home Assistant. I recommend taking this route, unless you have the
problem described next.
NodeRed has become pickier in error checking the responses from the INIM system, at least in my
case, with 2014 firmware, which cannot be updated. Apparently, one of the response headers is in
the wrong order. NodeRed generates an error (Postman does not). None of the workaround I tried in
NodeRed worked.
Two workarounds
I created two command_line sensors in Home Assistant as follows, one form scenario states and for
alarm states:
5
I then poll these HA sensors in NodeRed to set the scenario and alarm states. Command_line sensors
can only contain less than 255 bytes. So if the response from the INIM server contains more data,
the command_line sensor cannot be used.
For these situations I created a second workaround by creating two “rest” sensors, using the “rest”
integration (note, this is different than “restful”!!) in a “rest.yaml” file as follows. Including
json_attributes ensures the data are stored in “zone” and “part” attributes, without quantity
limitation:
By polling these two sensors in NodeRed it is easy to navigate to the data you need.
6
Getting the alarm log (10, 20, 60 lines) and showing it in Home Assistant
This is the most difficult part. It required learning quite a few new nodes in NodeRed and some
javascript.
save_inim_alarm_report_to_disk_as_json: >
'curl -k "http://192.168.1.92:5050/cgi-bin/web.cgi
?mod=log&par={{states("input_number.inim_report_lines")}}&
user=xxx&pass=yyy&code=zzz" -o "/share/inim/output_from_inim_as_json.txt" '
• We then delete the previous version of the report in the (local) destination directory
• We read the json formatted report from disk and format it as proper json.
• The next node reverses the line sorting to get the most recent alarm line on top; the results
is put in “msg.payload”;
• The output goes into a “moustache” html template to create a simple html table;
• The next function node creates a filename, that is used to write the output to an html file on
the /share/inim directory (NodeRed is not allowed to write directly into the /config/www
directory);
• The next function node generates a random number between 1 and 10.000 which gets
added to the directory+filename string. The output from the /share/inim is then copied to
/local, using this filename with random number. A lovelace (iframe)webpage can only be
read from a /local directory (which is equal to “/config/www/”).
We need to add a random number because the frontend needs to see a file with a new
name each time the file changes. Otherwise it just shows what is in the browser cache. I
have not found a way to easily flush the browser cache from HA.
• The filename string with random number gets stored in a HA entity for use in the frontend.
• You can find the NodeRed code for this flow in pastebin.com
7
And don’t forget to add to the “configuration.yaml” file the authorization (for NodeRed) to write
to the /share directory:
homeassistant:
allowlist_external_dirs:
- /config
- /share
Frontend programming
The frontend uses the “browser_mod” add-on package to create a popup for the alarm report when
the button gets pressed. It also uses the “config-template-card” that adds templating functionality to
Lovelace cards. This is necessary to be able to call the html page with the random number in the file
name, to ensure we get a new page whenever the alarm report changes.
type: vertical-stack
title: Alarm report
cards:
- type: entities
entities:
- type: custom:slider-entity-row
entity: input_number.inim_report_lines
name: Aantal regels
hide_state: false
icon: none
- entity: sensor.alarm_report_filename_random
name: Filename
icon: none
show_header_toggle: false
- show_name: true
show_icon: true
type: button
entity: input_number.inim_report_lines
icon: mdi:receipt
icon_height: 50px
name: Get latest
tap_action:
action: fire-dom-event
browser_mod:
service: browser_mod.popup
data:
title: Latest alarm report
size: wide
autoclose: false
content:
type: custom:config-template-card
8
variables:
FILE_NAME: states['sensor.alarm_report_filename_random'].state
entities:
- sensor.alarm_report_filename_random
card:
type: iframe
url: ${'/local/alarm/html/'+ FILE_NAME}
target:
device_id:
- yyyyyyyyyyyyy # get these from the browser_mod integration
- xxxxxxxxxxxxx
show_state: false
show_name: true
9
API parameters summary
10