Smart Friends Bridge Addon

I created 2 addons to integrate the German automation hub Smart Friends into Home Assistant. There is a simple REST gateway which can be polled for information and there is also an MQTT variant which once you have mapped the Smart Friends device ID to a hassio device type, they will be available in the MQTT integration.

My addon repository is at https://github.com/GimpArm/hassio-addons

The Smart Friends hub has support for a number of proprietary devices like the Schellenberg line of automated shades (Rollladen). It also has Z-Waze and Zigbee support. Although I’ve found that anything beyond a simple switch or sensor isn’t supported.

With my addons the devices integrated seamlessly and easily into the hassio environment.

1 Like

Thank you for the great addon. Since today I am getting an error: CERT_HAS_EXPIRED.
Do we probably need a new CA.pem file?

Thank you in advance

I have no problems connecting nor have I heard reports from anyone else. There is an embedded certificate but this is extracted from the SmartFriends Android app. I just checked this certificate and it expires on Oct 27 07:58:26 2036 GMT. So I don’t think this is a problem with the bridge.

I suspect your system clock is wrong or the SmartFriend’s clock is wrong. Usually expiration errors on valid certificates are to do with incorrect system times. Try checking your date information and if that doesn’t work then post the full error message.

Thank you for your reply, you were right. I have blocked access to the internet for my smartfriendsbox in order to avoid automatic upgrades. It probably did’t synchronise the time correctly. I opened the firewall, and after upgrading to 2.20 it is now working, both your integration as well as the original node scripts from LaPablo.

Hello Gimp Arm,
First of all, thank you very much for the great add-on. I’m new to the Home Assistant area and I can’t get my Schellenberg shutters up. The button for it is dark. In addition, the status is not displayed to me. What can I do?
Thank you

Yeah, I can help. First I need to know if you’re using the REST functionality or the MQTT. I also need you to post the output of the /list call, so something like http://yourhassioip:5001/list

Also, it definitely works from the SmartFriends official app? If it doesn’t work there then its not going to work here.

Hello GimpArm,
i’m using REST. Yes, it works with the offical App from SmartFriends. This is my output:

[
  {
    "id": 16551,
    "name": "Rolladen Balkon rechts",
    "room": "DiningRoom",
    "gatewayDevice": "SmartFriendsBox",
    "kind": "RollingShutter",
    "manufacturer": "Alfred Schellenberg GmbH",
    "state": "Down",
    "devices": {
      "rollingShutter": {
        "Id": 16551,
        "description": "SchellenbergRadioMotor_Unidirectional",
        "commands": {
          "Stop": 0,
          "Up": 1,
          "Down": 2
        },
        "currentValue": "Down"
      }
    }
  },
  {
    "id": 5055,
    "name": "Rolladen Balkon links",
    "room": "DiningRoom",
    "gatewayDevice": "SmartFriendsBox",
    "kind": "RollingShutter",
    "manufacturer": "Alfred Schellenberg GmbH",
    "state": "Down",
    "devices": {
      "rollingShutter": {
        "Id": 5055,
        "description": "SchellenbergRadioMotor_Unidirectional",
        "commands": {
          "Stop": 0,
          "Up": 1,
          "Down": 2
        },
        "currentValue": "Down"
      }
    }
  }
]

And this is my entry in configuration.yaml:

cover:
  - platform: template
    covers:
      shutter_balkon_rechts:
        friendly_name: "Rolladen Balkon rechts"
        device_class: shutter
        position_template: "{{ states('sensor.shutter_position_balkon_rechts') }}"
        open_cover:
          service: shell_command.shutter_up
          data:
            device_id: 16551
        close_cover:
          service: shell_command.shutter_down
          data:
            device_id: 16551
        stop_cover:
          service: shell_command.shutter_stop
          data:
            device_id: 16551
        set_cover_position:
          service: shell_command.shutter_position
          data_template:
            device_id: 16551
            position: "{{ position }}"

Ok, for some reason it isn’t finding the position sensor, among others. Can you post the output of http://yourhassioip:5001/raw ?

Also, can you show me your shell_command definitions?

Hello GimpArm,
yes, I saw that the sensor says only “unbekannt”.
This are my shell commands:

shell_command:
    shutter_up:        "curl http://myhassioip:5001/set/16551/rollingShutter/up"
    shutter_down:      "curl http://myhassioip:5001/set/16551/rollingShutter/down"
    shutter_stop:      "curl http://myhassioip:5001/set/16551/rollingShutter/stop"
    shutter_position:  "curl http://myhassioip:5001/set/16551/{{ 100 - position }}"

When I open http://myhassioip:5001/raw I can see a long list with all settings of my SmartFriends box.

Regards,
Tom

The first example in the documentation is bad, I’ll fix that. You need to make the device id in the command a variable {{ device_id }}

So like:


shell_command:
    shutter_up:        "curl http://myhassioip:5001/set/{{ device_id }}/rollingShutter/up"
    shutter_down:      "curl http://myhassioip:5001/set/{{ device_id }}/rollingShutter/down"
    shutter_stop:      "curl http://myhassioip:5001/set/{{ device_id }}/rollingShutter/stop"
    shutter_position:  "curl http://myhassioip:5001/set/{{ device_id }}/{{ 100 - position }}"

Although based on your data from /list there is no position sensor so that won’t work. If you can show me the entire output of /raw then I can check if position is a possibility or not. You might not have one in which case it can be set by time in Hassio but if anyone moves them outside of Hassio then it won’t know the position.

Hello GimpArm,
this is my output of http://myhassioip:5001/raw.

https://1drv.ms/w/s!Ajg1jIUaDGS06CxB2Yyt5KyilX9q?e=Dyc7BO

Regards,
Tom

I’m sorry, I should have clarified, I need the raw output directly after a restart of the addon. You can use https://pastebin.com to share it more easily.

After you changed the shell_commands, where the devices working better?

Hello GimpArm,

Immediately after the restart I only get a message from the browser that the connection was refused and then this output appears immediately.

Changing the shell_commands did not help, the sensor still shows the status unknown. I will now send you my complete configuration entries because I think I have configured anything wrong:

shell_command:
    shutter_up:        "curl http://20.20.20.104:5001/set/{{ 16551 }}/rollingShutter/up"
    shutter_down:      "curl http://20.20.20.104:5001/set/{{ 16551 }}/rollingShutter/down"
    shutter_stop:      "curl http://20.20.20.104:5001/set/{{ 16551 }}/rollingShutter/stop"
    shutter_position:  "curl http://20.20.20.104:5001/set/{{ 16551 }}/{{ 100 - position }}"


    

cover:
  - platform: template
    covers:
      shutter_balkon_rechts:
        friendly_name: "Rolladen Balkon rechts"
        device_class: shutter
        position_template: "{{ states('sensor.shutter_position_balkon_rechts') }}"
        open_cover:
          service: shell_command.shutter_up
          data:
            device_id: 16551
        close_cover:
          service: shell_command.shutter_down
          data:
            device_id: 16551
        stop_cover:
          service: shell_command.shutter_stop
          data:
            device_id: 16551
        set_cover_position:
          service: shell_command.shutter_position
          data_template:
            device_id: 16551
            position: "{{ position }}"

sensor:
  - platform: command_line
    name: shutter_position_balkon_rechts
    command: "curl http://20.20.20.104:5001/get/16551/position"
    unit_of_measurement: "%"
    scan_interval: 5
    value_template: '{{ 100 - value_json.currentValue }}'

I just noticed that I had an error in the log:

2021-08-26 20:09:48 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ 100 - value_json.currentValue }}'

It should literally be device_id and not the actual ID. It gets the actual ID from the cover template.

shell_command:
    shutter_up:        "curl http://20.20.20.104:5001/set/{{ device_id }}/rollingShutter/up"
    shutter_down:      "curl http://20.20.20.104:5001/set/{{ device_id }}/rollingShutter/down"
    shutter_stop:      "curl http://20.20.20.104:5001/set/{{ device_id }}/rollingShutter/stop"
    shutter_position:  "curl http://20.20.20.104:5001/set/{{ device_id }}/{{ 100 - position }}"


    

cover:
  - platform: template
    covers:
      shutter_balkon_rechts:
        friendly_name: "Rolladen Balkon rechts"
        device_class: shutter
        position_template: "{{ states('sensor.shutter_position_balkon_rechts') }}"
        open_cover:
          service: shell_command.shutter_up
          data:
            device_id: 16551
        close_cover:
          service: shell_command.shutter_down
          data:
            device_id: 16551
        stop_cover:
          service: shell_command.shutter_stop
          data:
            device_id: 16551
        set_cover_position:
          service: shell_command.shutter_position
          data_template:
            device_id: 16551
            position: "{{ position }}"

sensor:
  - platform: command_line
    name: shutter_position_balkon_rechts
    command: "curl http://20.20.20.104:5001/get/{{ device_id }}/position"
    unit_of_measurement: "%"
    scan_interval: 5
    value_template: '{{ 100 - value_json.currentValue }}'

Although you’re getting the error because the bridge has no knowledge of the position sensor. I suspect there is no position sensor and the app just does it based on time. Maybe you had to calibrate how long it takes to go up and down and when you tell it to go to 50% it just does 50% of the time. I bet if you moved the shutters outside their app, it would not have the correct position.

The only way I can confirm if you have a position sensor or not is by that raw dump. So I urge you to try it again.

If you don’t have a position sensor then I suggest you look into using something like this: Custom Component: Cover Time Based

I could add a time based position into my bridge but if you ever moved the shutter outside the bridge then it would lose track and I’m not sure how to regain it. I’ll have to think about it more and maybe I can come up with something I’ll be happy with.

Hi @GimpArm ,
thanks a lot for the smartfriends add-on. I am using the MQTT way to get the shutters into HomeAssistant and they show up just fine. I can also control them via HomeAssistant, but HomeAssistant does not correctly reflect the state of these shutters.
F.E. I just closed one shutter and in the add-on log I can see that it correctly received the new state from the Smartfriends box, but it did not forward this new state change to MQTT, so I think something is not working correctly in the add-on.

Second issue, or rather question: Is there any way to get some sort of “busy” state while the shutters are moving? I am asking because I would like to have a physical two button control for the shutters, and the automation logic needs to know what the shutter is currently doing so that it can act accordingly (stop, move opposit direction etc).
edit: hmm, some shutters seem to report their position, others do not and also have far less attributes. But regarless of that, in HA the device state is for all unknown

I also get these errors from MQTT

Logger: homeassistant.components.mqtt.cover
Source: components/mqtt/cover.py:372
Integration: MQTT (documentation, issues)
First occurred: 08:27:03 (12 occurrences)
Last logged: 08:27:03

Payload is not supported (e.g. open, closed, opening, closing, stopped): "Stop"

Sorry for the delay, I will try to help you but I broke my leg and I’m not as active at the moment.

First step would be to check the current state in the smartfriends bridge. So we can narrow down whether it is the MQTT side or the smartfriends side. Go to what ever address you have set up in your browser http://homeassistant:5001/list You will see the data how my system Interprets it from the smartfiends hub. Under “devices” you should see a “position” entry which has a “currentValue” value. If you do not see this there is a chance your shutters do not report their current position. I only have Schellenberg Rollodrive 65 Premium in my house and I know those report position but I know there are some models that do not. If you believe yours do report position but you are not seeing it in the list then I would need you to send me the output from http://homeassistant:5001/raw a few seconds after the plugin has newly started. That is the data I get from the smartfiends hub and based on that I can tell you what information is available. There is no private data in that, only your device names but nothing more.

For busy state, I can only tell you what the smartfreinds hub makes available. For my shades each device has a “rollingShutter” device which has a “currentValue” of either up, down, or stop. That would be your busy indicator. When it is up or down then you know it is moving. If you want to make use of this you can edit your /config/smartfriends2mqtt/typeTemplate.json and change it based on the HASSIO documentations MQTT Cover - Home Assistant

The error you see in your logs I also get but things had been working so I didn’t investigate further. Based on the above linked documentation the error probably comes because I just pass the “Stop” directly from the hub This is the value set by the entry that state_topic points to. I don’t want my system to be editing values because then for every device I have to release a new version. Its better to leave that up to the integration. My understanding of the documentation is that I can fill out state_closing, state_opening, and state_stopped with the values the hub sends (up, down, stop) and HASSIO is supposed to map that state_topic value itself. Now clearly this isn’t happening, either I understand that documentation incorrectly or there is a bug in HASSIO and I should probably make a post here asking for developer support. If I understand it wrong then I’ll probably have to add a mapping function in the templates, so the values can be mapped in the config because like I said I don’t want to hardcode values like that into the system.

A tip if you’re using MQTT. I like to use MQTT Explorer to look at exactly what is going on. You can see under homeassistant/cover/sf_* will be your devices and the config based on the template that I send to hassio. Then under smartfriends2mqtt you see the raw values that get sent. Those raw values are accessible to use in HASSIO as long as you define the template.

Thanks for your help. I can confirm that I can see position values in the JSON output of your add-on, but for some covers it’s missing there as well, so I suppose those motors do not support this feature as you mentioned.
For me personally it’s unfortunately also difficult to debug, since I am helping a friend in this case and I can only VPN into his HA installation and also do not know all the details of his hardware setup (like which motors are used). I only know that he didn’t listen to my advice before he got those darn closed eco-system motors instead of just “dumb” Schellenberg motors with an additional Zwave or Zigbee actuator, and that I can now try to fix his utterly borked setup, since all of a sudden he wants to control the shutters via regular GIRA wall switches (since the crappy Schellenberg wirless switches can’t be mounted on a in-wall socket and also look terrible) :frowning:

as for the “busy state” of “up/down/stop” - that seems to be not accurate, since some shutters are stuck in “up” or “down” state but they are not moving at all. This is why I suspect some state updates the add-on notices are not correctly forwarded to MQTT.
I’ll try to do some debugging via MQTT explorer, but since I kinda lost interest in fixing my friends crap atm, it might take some time.

edit: almost forgot - get well buddy