Introduction

Home Assistant is perhaps the newest member in the family of home automation software: the slogan of this home automation software is simplicity. It was developed on Python and in the same way as Domoticz, you can expand its functionality using plugins/add-ons. Home Assistant is available as a ready-made operating system (image) for Raspberry PI or as a virtual machine image for PC with Windows, MacOS, Linux (KVM, VirtualBox, VMware). As a Docker container, Home Assistant can also run in your own environment, which you manage yourself. No special compilation and configuration skills required!

NetControl and Home Assistant

Home Assistant has built-in support for SNMP and MQTT protocols. Any of them can be used to integrate NetControl, but MQTT definitely gives more capabilities, especially in that NetControl data is entered into home assistant in real time (unlike SNMP, where "polling" is used and devices are "asked" about their status at a certain intervals of time).

Adding one or more NetControl devices is done manually by editing the configuration.yaml file (note that groups of two spaces are used to structure the data!). For greater convenience when working with YAML files, we recommend that you install your 'Studio Code Server' add-on.

'switch' and 'sensor' (these are the so-called 'integrations') are two of the types that Home Assistant uses as a definition of the type of channel of a device (and the data it accepts/transmits). The "switch" group includes NetControl relay outputs – i.e. we can submit On/Off commands to them and receive their current status. The 'sensor' group covers all NetControl inputs that can only send data to the Home Assistant - alarm inputs, sensor inputs (temperature, humidity, etc.), voltage measurement, current, pulses, etc. Of course, there are other types of 'integrations' such as light, binary sensor, etc. You can also use them, according to the situation - very often they have similar setting parameters.

Integration over SNMP

The following are examples of adding the 'Line 1' relay output and NetControl's temperature input 'Sensor 1' (e.g. 2R2S1A, 4R4S1A models). Please note that if you already have sections 'swtich' and 'sensor' in the configuration file, you only need to add the code to the available sections (as it is not permissible to have multiple definitions for them).

switch:
- platform: snmp
scan_interval: 10 # state polling interval in seconds
name: "Netcontrol_SNMP_Line1" # Name of this NetControl channel in Home Assistant
host: 192.168.1.100 # IP address of your NetControl Device
version: "1"
auth_protocol: none
priv_protocol: none
payload_on: 1
payload_off: 0
vartype: Integer
# Enter here your R/W community string
community: private
# Line 1 uses [P]=9. Change to another value, according to model (see manual)
baseoid: 1.3.6.1.4.1.19865.2.3.1.9.6.0 sensor:
- platform: snmp
scan_interval: 10
name: "Netcontrol_Temperature_TDS300"
host: 192.168.1.100
version: "1"
auth_protocol: none
priv_protocol: none
community: private
baseoid: 1.3.6.1.4.1.19865.2.3.1.25.6.0 # Channel with [P]=25
unit_of_measurement: "C"
# Template to convert raw SNMP value to temparature
value_template: "{{(((3300 * (value | float) / 1023) - 500) / 10) | round(1)}}"

Integration over MQTT

IMPORTANT REQUIREMENTS !!!
1. MQTT requires the presence of a so-called broker. Home Assistant offers one in the form of an add-on 'Mosquitto broker' - use it if you don't already have another broker installed.
2. The MQTT broker uses home assistant's "Users" system for authorization. It is best to define a new user in the system, specifically for the login of MQTT clients. The Home Assistant user/password/IP address must be entered in the MQTT NetControl settings.
3. In NetControl's MQTT settings, you also must to set 'PUBLISH value format' = JSON and 'Mirror /in to /out' = YES

The following are examples of adding 'Line 1' relay output, NetControl's 'Sensor 1' with temperature sensor installed (e.g. 2R2S1A, 4R4S1A) and alarm input (Alarm1 of 2R4A in example), but now based on the MQTT protocol.

The last 3 sections illustrate the addition of a NetControl 4PC2R input. In addition to the mqtt definition, two more blocks of "statistics" and "template" were added to the system. Their purpose is to be able to obtain information about the power of the load (e.g. if we have a connected electricity meter to the pulse input) by calculating the difference between the new and the previous reading of the meter. These last two measurements come from the "statistics" module, the most important being that 'entity_id' points to the sensor object from which the data comes from (in this case:sensor.pulse_counter_1); with the other parameters we indicate that we are interested in the last two reports and if there is no data more than5 min to give zero value. The 'template' section is used to apply the load calculation itself according to the meter constant (imp/kWh) and the built-in parameter'change_rate' (it calculates the difference between the last two values divided by the time difference between their measurements in seconds).

mqtt:
  - switch:
      unique_id: uid_switch1
      name: "NetControl_A_CH1"
      # next topics must match your NetControl's settings for 'User defined sub-topic' and desired channel
      state_topic: "NetControl/subgroup/out/ch9"
      command_topic: "NetControl/subgroup/in/ch9"
      payload_on: "ON"
      payload_off: "OFF"
      state_on: "ON"
      state_off: "OFF"
      retain: true
      value_template: "{{value_json.value.real}}"

- sensor: unique_id: id_sensor_hum1 name: "NetControl_Hummidity" # topic must match your NetControl's settings for 'User defined sub-topic' and desired channel state_topic: "NetControl/subgroup/out/ch25" unit_of_measurement: "%" # NetControl sends dimension with value, but HomeAssistant doesn't like it - so trim it! value_template: '{{value_json.value.real|trim("%")}}'
- binary_sensor: unique_id: uid_alarm1 name: "NetControl_Door1" state_topic: "NetControl/subgroup/out/ch26" payload_on: "OPEN" payload_off: "CLOSED" device_class: door value_template: "{{value_json.value.real}}"
- sensor: name: "pulse_counter_1" state_topic: "NetControl/subgroup/out/ch20" value_template: "{{value_json.value.raw}}" force_update: true

sensor: - platform: statistics entity_id: sensor.pulse_counter_1 name: pulse_stat_change state_characteristic: change sampling_size: 2 max_age: minutes: 5 # to set zero power value if MQTT data is not received by some reason template: - sensor: - name: "Current load" # Change 1600 with your device's imp/kWh constant state: "{{ (states('sensor.pulse_stat_change') | float * 1000 * 3600 / 1600) | round(1) }}" unit_of_measurement: "W"

After changes in configuration.yaml it is necessary to reload or restart HA. The newly defined channels will appear in the Integrations / Entities menu. You can then select them as your graphics data source and more.

Theese example YAML definitions can be downloaded here: