Smart Home Christmas challenge

If you find yourself with some spare time over the Christmas holidays and want to bridge the gap between your local hardware and the cloud, this project is for you. We will integrate your smart home devices into a professional IoT ecosystem.

Goal

Our objective is to visualize measurements, track events, and manage alarms from Homematic sensors directly within a Cumulocity IoT tenant.

:hammer_and_wrench: Hardware & Software Requirements

:satellite_antenna: Sensors & Gateway

  • Homematic CCU: You need a running instance of OpenCCU.
  • Homematic Devices: Any Homematic IP hardware installed at your home (e.g., thermostats, door contacts, or weather stations).

:house: Smart Home Central

:cloud: Cloud Connection


:triangular_ruler: System Architecture

Below is the full picture of my setup, showing the data flow from the physical sensor through the local gateway to the cloud dashboard.

Installation

Step 1: Install Homematic CCU on IP 192.168.2.4 can be dynamic
Step 2: Install Home assistant on IP 192.168.2.5 static
Step 3: Install thin-edge on IP 192.168.2.6 static

Configuration - the interesting part

Homematic

Please excuse that this is not mentioned here

Home Assistant

As a first step you need to integrate Homematic into Home assistant. Here en.Installation · OpenCCU/OpenCCU Wiki · GitHub you can find a pretty good way to do so. Please follow this HomeAssistant Integration · OpenCCU/OpenCCU Wiki · GitHub article to do so.

As second step you need to have MQTT enabled to publish the data to the thin edge Broker. MQTT - Home Assistant.

# make sure you have installed the mosquitto client on the HA device
sudo apt update
sudo apt install mosquitto-clients -y

### Configuration to connect to thin-edge.io
connection:     192.168.2.6
port:           1883
username:       leave blank
password:       leave blank

thin-edge

After installing thin-edge on your device, you need to connect it to Cumulocity IoT. The easiest way to do this is by using a CA certificate.
Navigate to your Cumulocity tenant at Device Management and click the “Add CA certificate” button to add your CA certificate.

Identify your serial number - best practice

## get the Serial number
cat /proc/cpuinfo | grep Serial | awk '{print $3}'
output = 100000000a29e3a7 
or
output =  0123ab32fcd

Set your tenant

## set tenant url
sudo tedge config set c8y.url "ABCD.eu-latest.cumulocity.com"

Register your device

Once this is complete, register your thin-edge device in Cumulocity at Device Management. Provide the serial number and a one-time password. Save this information as you will need it for the next step.

With this command on the thin-edge shell your finish up your registration:

sudo tedge cert download c8y --device-id "100000000a29e3a7"

# Or provide the one-time password via the flag
sudo tedge cert download c8y \
    --device-id "100000000a29e3a7" \
    --one-time-password "$DEVICE_ONE_TIME_PASSWORD"

Configure thin-edge broker

By default, the thin-edge broker is restricted to accept connections only from thin-edge itself. To allow MQTT connections from external clients, you need to modify the broker configuration.
Edit your thin-edge Mosquitto configuration file located at:

/etc/tedge/mosquitto-conf/tedge-mosquitto.conf

Default config:

# pre configured configuration
# 
listener 1883 127.0.0.1

Change this to the following configuration to allow MQTT connections from external clients:

# pre configured configuration
# 
listener 1883 0.0.0.0

Automation on Home Assistant and thin-edge

Identify your sensors with Serial numbers

Within the developer tools Developer tools - Home Assistant filter on states starting with sensors.

Find your sensors

To find your sensors, navigate to Developer Tools in Home Assistant and select the Template tab. Enter the following code:

{% for state in states -%}
Name: {{ state.name }}
ID: {{ state.entity_id }}
Modell: {{ state.attributes.model | default(state.attributes.device_class, true) | default('N/A', true) }}
Adresse: {{ state.attributes.address | default(state.attributes.ip_address, true) | default(state.attributes.ip, true) | default('keine Adresse gefunden', true) }}
---------------------------------------
{% endfor %}

You will get a list like:

---------------------------------------
Name: Living Room-Thermostat Temperatur
ID: sensor.wohnzimmer_thermostat_temperatur
Modell: HmIP-WTH-1
Adresse: 00391F29AD6EA:1
---------------------------------------

Assign your sensors to your device and find out its serial number

# this is an example of an event but it shows at least the values you get from home assistant 
binary_sensor.00109d8995977_low_bat # this is the variable you need
HmIP-SWDO-I Wohnzimmer Fenster LOW_BAT
off
 id: 00391F29AD6EA                 # this is your serial number
interface: ip
battery: High
sabotage: No
rssi_device: -63
voltage: 2.8
device_class: battery
friendly_name: HmIP-SWDO-I Wohnzimmer Fenster LOW_BAT

In the following steps, you will send measurement values from the sensor variable sensor.wohnzimmer_thermostat_temperatur to the thin-edge device 00391F29AD6EA. For example, you might send a temperature value of 21 degrees.

Create child devices

To organize your sensors in thin-edge, you need to register them as child devices before creating automations. This allows thin-edge to map your local sensors to the correct device hierarchy in Cumulocity.

Please execute the following commands to create the child devices.

# register child devices
# Wohnzimmer
tedge mqtt pub -r 'te/device/00391F29AD6EA//' '{
  "@type": "child-device",
  "name": "00391F29AD6EA",
  "type": "HmIP-WTH-1"
}'
# Bathroom 
tedge mqtt pub -r 'te/device/00391F29AD8C6//' '{
  "@type": "child-device",
  "name": "00391F29AD8C6",
  "type": "HmIP-WTH-1"
}'
# office
tedge mqtt pub -r 'te/device/OEQ2089075//' '{
  "@type": "child-device",
  "name": "OEQ2089075",
  "type": "HM-CC-RT-DN"
}'

# Kitchen
tedge mqtt pub -r 'te/device/000A98A9A74A2//' '{
  "@type": "child-device",
  "name": "000A98A9A74A2",
  "type": "HHmIP-WTH-2"
}'

Create measurements.yaml within Home assistant

Once your child devices are registered in thin-edge, create your first Home Assistant automation file to send measurements. The following automation publishes all sensor measurements to thin-edge every 5 minutes.

Note: Pay close attention to YAML indentation and formatting. Incorrect spacing will cause the automation to fail.

id: 'cumulocity_living_room_all_measurements'
alias: MQTT Send - Data to thin-edge (MEASUREMENTS)
description: Sends all quantitative measurement values  in one batch.
trigger:
  - platform: time_pattern
    minutes: "/5" # every 5 minutes
action:
  - service: mqtt.publish
    data:
      topic: te/device/00391F29AD6EA///m/LivingRoom
      qos: 1
      retain: false
      payload: >
        {% set data = {
          "Temperature": states('sensor.wohnzimmer_thermostat_temperatur') | float(0),
          "Humidity": states('sensor.wohnzimmer_thermostat_luftfeuchtigkeit') | float(0),
          "Operating_Voltage": states('sensor.wohnzimmer_thermostat_betriebsspannung') | float(0),
          "RSSI_device": states('sensor.wohnzimmer_thermostat_rssi_device') | int(0),
          "RSSI_peer": states('sensor.wohnzimmer_thermostat_rssi_peer') | int(0)
        } %}
        {{ data | to_json }}
  - service: mqtt.publish
    data:
      topic: te/device/000A98A9A74A2///m/Kitchen
      qos: 1
      retain: false
      payload: >
        {% set data = {
          "Temperature": states('sensor.kuchen_thermostat_temperatur') | float(0),
          "Humidity": states('sensor.kuchen_thermostat_luftfeuchtigkeit') | float(0),
          "Operating_Voltage": states('sensor.kuchen_thermostat_betriebsspannung') | float(0),
          "RSSI_device": states('sensor.kuchen_thermostat_rssi_device') | int(0),
          "RSSI_peer": states('sensor.kuchen_thermostat_rssi_peer') | int(0)
        } %}
        {{ data | to_json }}
  - service: mqtt.publish
    data:
      topic: te/device/00391F29AD8C6///m/Bathroom
      qos: 1
      retain: false
      payload: >
        {% set data = {
          "Temperature": states('sensor.bad_thermostat_temperatur') | float(0),
          "Humidity": states('sensor.bad_thermostat_luftfeuchtigkeit') | float(0),
          "Operating_Voltage": states('sensor.bad_thermostat_betriebsspannung') | float(0),
          "RSSI_device": states('sensor.bad_thermostat_rssi_device') | int(0),
          "RSSI_peer": states('sensor.bad_thermostat_rssi_peer') | int(0)
        } %}
        {{ data | to_json }}
  - service: mqtt.publish
    data:
      topic: te/device/OEQ2089075///m/Office
      qos: 1
      retain: false
      payload: >
        {% set data = {
          "Temperature": states('sensor.thermostat_buro_temperatur') | float(0),
          "Operating_Voltage": states('sensor.thermostat_buro_batteriezustand') | float(0),
          "RSSI_peer": states('sensor.thermostat_buro_rssi_peer') | int(0)
        } %}
        {{ data | to_json }}              
mode: single

After reloading the YAML configuration, your child devices will receive the measurements from Home Assistant.

Adding units to measurements

The automation above sends only measurement values without units. To make the data more useful in Cumulocity, define the unit for each measurement. Execute the following commands to add unit metadata:

# define Measurement Units
tedge mqtt pub -r 'te/device/00391F29AD6EA///m/LivingRoom/meta' '{
  "Temperature": {
    "unit": "°C"
  },
  "Humidity": {
    "unit": "%"
  },
  "Operating_Voltage": {
    "unit": "V"
  },
  "RSSI_peer": {
    "unit": "dBm"
  },
  "RSSI_device": {
    "unit": "dBm"
}'

tedge mqtt pub -r 'te/device/00391F29AD8C6///m/Bathroom/meta' '{
  "Temperature": {
    "unit": "°C"
  },
  "Humidity": {
    "unit": "%"
  },
  "Operating_Voltage": {
    "unit": "V"
  },
  "RSSI_peer": {
    "unit": "dBm"
  },
  "RSSI_device": {
    "unit": "dBm"
}'

tedge mqtt pub -r 'te/device/OEQ208907///m/Office/meta' '{
  "Temperature": {
    "unit": "°C"
  },
  "Operating_Voltage": {
    "unit": "V"
  },
  "RSSI_peer": {
    "unit": "dBm"
  },
}'



tedge mqtt pub -r 'te/device/000A98A9A74A2///m/Kitchen/meta' '{
  "Temperature": {
    "unit": "°C"
  },
  "Humidity": {
    "unit": "%"
  },
  "Operating_Voltage": {
    "unit": "V"
  },
  "RSSI_peer": {
    "unit": "dBm"
  },
  "RSSI_device": {
    "unit": "dBm"
}'

Create events.yaml

To send events like door open/close status changes, create an automation following this same structure. Important: Events and Alarms are sent to the main thin-edge device, not to child devices.

To identify the sensors that trigger these events, use Home Assistant’s Developer Tools. Navigate to Developer tools - Home Assistant and filter the state list to find binary sensors related to your events.

You will see a list like this:

binary_sensor.00109d8995977_state ## this is what we are looking for
HmIP-SWDO-I Wohnzimmer Fenster STATE
off                         ## this is the state which changes off = door is closed on = door is open 
 id: 00109D8995977
interface: ip
battery: High
sabotage: No
rssi_device: -63
voltage: 2.8
device_class: opening
friendly_name: HmIP-SWDO-I Wohnzimmer Fenster STATE

Here is an example events.yaml file

id: 'cumulocity_fenster_state_event_living_room'
alias: MQTT Send - thin-edge (EVENTS) living room
description: Sends an event when the window is opened or closed.
trigger:
# Triggered whenever the window sensor changes state
- platform: state
  entity_id: binary_sensor.00109d8995977_state 
action:
  - service: mqtt.publish
    data:
      topic: 'te/device/main///e/window'
      payload: >
        {
          "type": "c8y_WindowStatus",
          "text": "Living Room Window Statusänderung: {{ trigger.to_state.state }}",
          "status": "{{ trigger.to_state.state }}"
        }
      qos: 1
      retain: false
mode: single

Tip: Create a separate YAML file for each event to keep your automations organized.

Create alarms.yaml

If your Homematic sensors support sabotage detection (window tampering), you can create an automation to trigger a critical alarm when tampering is detected. This is useful for security monitoring.

To find sabotage sensors, navigate to Home Assistant’s Developer Tools at Developer tools - Home Assistant and filter for binary sensors with “sabotage” in their entity ID.

# here is an example
binary_sensor.hmip_swdo_i_kuche_tur_sabotage # this is need
HmIP-SWDO-I Kitchen Door Sabotage
off                                         # here is our event
 interface_id: RaspberryMatic-HmIP-RF
address: 00109D89959B4:0
model: HmIP-SWDO-I
parameter: SABOTAGE
function: Energiemanagement,Umwelt,Heizung
value_state: valid
device_class: tamper
friendly_name: HmIP-SWDO-I Kitchen Door Sabotage

So lets create an automation which creates an alarm and clear an alarm if the event goes to off again.

id: 'cumulocity_sabotage_alarm_kitchen'
alias: "MQTT Senden - Sabotage Alarm Kitchen"
description: "Sends a critical alarm in case of tampering (on) and clears it (off)."
trigger:
  - platform: state
    entity_id: binary_sensor.hmip_swdo_i_kuche_tur_sabotage
action:
  - action: mqtt.publish
    data:
      topic: 'te/device/main///a/sabotage_kitchen'
      payload: >
        {% if trigger.to_state.state == 'on' %}
          {
            "text": "Kitchen door Sabotage: ALARM",
            "severity": "critical"
          }
        {% else %}
          # it is important to send nothing and not "" nor '' to clear the alarm
        {% endif %}
      qos: 1
      retain: false
mode: single

With some magic you get

4 Likes

Nice. I am already using Home Assistant and will try that out for sure!

How about thin-edge as a Homeassistant Add-On? I run OpenCCU as an Add-On anyways and don’t really have hardware to spare :wink:

1 Like

Nice idea! Ideally it uses the central & available mosquitto of the HA addon. Not sure if this is feasible in regards to configuration needed for the Cumulocity (bridge) connection.