Using Homematic switch as sensor state in Homeassistant

Hey Guys,

just to share the knowledge:
I wanted to integrate Homematic physical Buttons (e.g. HMIP-WRC2) to set states in Homeassistant (through a binary sensor).
Therefore, I set up the button in homematic, which than, after pressing, changes a system variable in homematic. Therefore I wrote a program in homematic:


If the button is pressed, the System variable changes from 0 to 1:

In hassio, you need to define the sensor in the config.yaml:

homematic:
  interfaces:
    rf:
      host: 192.168.xx.xx
      resolvenames: "json"
      username: Admin
      password: xxx
    ip:
      host: 192.168.xx.xx
      port: xx
      resolvenames: json
      username: Admin
      password: xx
    groups:
      host: 192.168.xx.xx
      port: xx
      resolvenames: "json"
      username: Admin
      password: xx
      path: /groups
  hosts:
    ccu3:
      host: 192.168.xx.xx
      port: xx
      username: Admin
      password: xxx
 
sensor:
  - platform: template
    sensors:
      anwesenheit_willi:
        friendly_name: "Willi_anwesend"
        value_template: "{{ state_attr('homematic.ccu3', 'Willi_anwesend') }}"
      anwesenheit_ossi:
        friendly_name: "Oskar_anwesend"
        value_template: "{{ state_attr('homematic.ccu3', 'Oskar_anwesend') }}"

After you did this, you will see a sensor in hassio:

From here, you can do whatever you want with this information, For example switch off the heating of your building when you leave the house or switch on/off the light etc etc.
Since there is no simple physical button available to integrate in homeassistant, I did this workaround. Have fun!
Alex

Thanks for your effort. But have you read the documentation? Here it’s explained how to use button-devices, which push events to Home Assistant. This happens instantly, so there’s no need to wait for the variables to be refreshed.

In any case: you should consider switching to the new integration: GitHub - danielperna84/custom_homematic: Custom Home Assistant Component for HomeMatic

There we have device automations for buttons, so everything can be done easily in the UI without listening for specific events.

1 Like

Hey Daniel,
THANK you for enlighten me… I had no clue about this new integration of yours. Thanks a lot for the effort, I just installed it to my system and start testing around.
Indeed I read the documentation, but seems like I got lost somewhere…
Anyways… Thanks again.
Nice weekend :wink:
Alex