Smart Friends Bridge Addon

Hi,

i’m using the smartFriends Bridge within Homeassistant with a SH1 Box. I can controll some Shutters but its not working very stable. I found some error messages in the logs. It seems like the API cannot parse the response from the box. Is it possible to enable some debug messages, so i can recognize response which leads to this message?

Error:

fail: SmartFriends.Api.Session[0]
Connection closed
Newtonsoft.Json.JsonReaderException: Additional text encountered after finished reading JSON content: {. Path ‘’, line 2, position 0.
at Newtonsoft.Json.JsonTextReader.Read()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at SmartFriends.Api.Client.Reader(Object input) in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Client.cs:line 218
fail: SmartFriends.Api.Session[0]
Refresh failed
null
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at SmartFriends.Api.Client.SendCommand(CommandBase command, Boolean skipEnsure, Int32 timeout) in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Client.cs:line 174
at SmartFriends.Api.Client.SendAndReceiveCommand[T](CommandBase command, Int32 timeout) in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Client.cs:line 143
at

I hope that someone has an idea
Tahnk you very much

The SmartFriends boxes started sending multiple json objects in a single message, which is technically invalid. I have a fix for it that I’ll be pushing out soon.

1 Like

Thank you very much! The Schellenberg API seems very strange.

@GimpArm Thank you very much for your fast update. Version 3.6 seems to be working fine and the JsonReaderException is not occurring anymore.

But there is one repeating error in the log. I don’t think, that it has any affect on the functionality, but perhaps someone can explain these errors.

fail: SmartFriends.Api.Session[0]
      Refresh failed
      null
      System.Threading.Tasks.TaskCanceledException: A task was canceled.
         at SmartFriends.Api.Client.SendCommand(CommandBase command, Boolean skipEnsure, Int32 timeout) in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Client.cs:line 175
         at SmartFriends.Api.Client.SendAndReceiveCommand[T](CommandBase command, Int32 timeout) in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Client.cs:line 144
         at SmartFriends.Api.Session.RefreshDevices() in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Session.cs:line 136 

@jme24 That error means the SmartFriends box isn’t responding in a proper time. It’s a timeout on the keepalive/status check call. This is done every 5 seconds. It could also be network issues.

Hi,
I use MQTT and with the template from the instructions my shutters are working again!
Thank you, great work.
ZWAVE and ZIGBEE will move to HA anyway, but what would be super important to me would be the “virtuellen Schalter”.
I’m assuming that in the deciveMap a virtual switch is just a switch?
So should it look like this?
{
“ID”: 206,
“Type”: “switch”,
}

Is that enough?
But what does the template have to look like?
Can someone please build a template for me? Because unfortunately I don’t have any idea to do that for myself
Many thanks for your help

If it really is just a simple on/off switch then that is enough. Add it to the smartfriends2mqtt/deviceMap.json file, restart the add-on and it will work. You can add a “Class” to it to help HA narrow down it a bit further, but switches only have a possible class of “switch” or “outlet” and it doesn’t change anything but the default icon. Switch - Home Assistant

Once you’ve restarted the add-on you should be able to find it in the devices section of HA with the name “roomName deviceName” you gave it in the SmartFriends app.

My bridge software will detect the default action and automatically map that, which works well for simple devices like switches and binary sensors. If you need more complex functionality, like RGB lights or shutters (which I include in the default template), then you need to either create a template or you can add the "Parameters":{} of that device’s mapping. For that you’ll need to read a lot about how HA does MQTT Discovery - Home Assistant and look at everything the device exposes in the REST interface going to http://ha.local:5001/get/12345 or what ever your HA url and the device ID is.

If it’s more then a simple switch, then post the result of the above url for that device and I can help you create a template.

Edit: Let me clarify, this is HIGHLY dependent on your device. No one can possibly predict what the device is going to report unless they have that exact device and have set it up. This is why Zigbee2MQTT has a huge list of supported devices but still you cannot buy any random device off the shelf and expect it to just work.

If your switch does not report the default ON/OFF values that HA expects, then you need to look at what you’re getting. Again this is in the above url I posted. If you see your “state” is “on” or “off” then you probably don’t need to do anything. If your state is something else, maybe 1 or 0, then you will probably need to set the payload and state values. You will see all supported commands as the value of commands property. Here is an example of one of my switches that doesn’t follow the HA standard:

What I put in my deviceMap.json file:

  {
      "Id": 14056,
      "Type": "switch",
      "Parameters": {
          "icon": "mdi:sprinkler",
          "state_on": 1,
          "state_off": 0,
          "payload_on": 1,
          "payload_off": 0,
          "assumed_state": true
      }
  }

This is what my SmartFriends add-on reports for this device

{
  "id": 14056,
  "name": "Sprinklers",
  "room": "Outside",
  "gatewayDevice": "SmartFriendsBox",
  "kind": "SwitchActuator",
  "manufacturer": "Zigbee",
  "model": "Plug 01",
  "state": 1,
  "devices": {
    "switchActuator": {
      "Id": 8815,
      "description": "ZigbeeSwitch",
      "commands": {
        "On": 1,
        "Toggle": 2,
        "Off": 0
      },
      "currentValue": 1
    },
    "failureStatus": {
      "Id": 13938,
      "description": "ZigbeeFailureDevice",
      "currentValue": 1
    }
  }
}

Hi,

Thank you very much for your explanations. I always assumed that all switches, lamps, etc. would be the same. So at least as far as the „code“ is concerned.

A virtueller Schalter is practically the same as an input boolean helper.

You can find it in the Smart Friends Box at:

„Bleistift“ pencil
„Weiteres Gerät hinzufügen“ (new device)
„-andere-„ ( others)
„Smart Control Funktion“
„Virtueller Schalter“ (Input Boolean)

After looking into my box, however, I believe that a virtual switch is not just a „simple switch“. At least as far as values are concerned.

Here is an example:

    "id": 5289,
    "name": "Flur Lampen",
    "room": "Flur",
    "gatewayDevice": "SmartFriendsBox",
    "kind": "SwitchActuator",
    "manufacturer": "${Manufacturer.SmartHomePartner}",
    "devices": {
      "switchActuator": {
        "Id": 14928,
        "description": "VirtualInput",
        "commands": {
          "On": 1,
          "Off": 0
        }
      },
      "wallSwitch": {
        "Id": 7382,
        "description": "VirtualOutput"
      }
    }
},

Following your example, it should look something like this, shouldn’t it?


{
      "Id": 5289,
      "Type": "switch",
      "Parameters": {
          "state_on": 1,
          "state_off": 0,
          "payload_on": 1,
          "payload_off": 0,
          "assumed_state": true
      }
  }

Best regards

Zigbee is kind of the wild west. It is a messaging protocol standard where the passing of the messages on devices is standard. Although, there is no one checking anything so there are poor implementations on the market that don’t play well all the time. Even when everything plays well together the message data itself is not standard or covered under the protocol. I can send you a letter through the postal service and you can receive it but if I wrote the letter’s content in Chinese then you might not be able to understand it. So someone has to look at the data being sent and try to figure it out. Zigbee2Mqtt has this monster collection of devices that people had to figure out. I’ve gone through the SmartFriends list of devices and there are some very strange ways of making messages for simple boolean devices.

Anyways, what you have looks like it will work. There is no “state” or “currentValue” property which is a little concerning but I assume this is just a button switch that is controlling something else. So in HA it might be better to try to combine them into a single entity since the control is in one button but the actual state of the device is another. So I guess it isn’t just “how does this device communicate” but also “what do you want it to do?”. Either way it is best to get the device communicating with HA then do all the changes for the exact behavior you want in HA directly, it is a much more powerful system with a lot of good documentation.

Hi,

Thanks so much

I’ll test it right away as soon as we get back from vacation :wink:

I would also prefer it, if I could just move to HA with everything. This would be my favorite goal. But unfortunately, this is not so easy with Schellenberg and Abus Smartvest (alarm system). Unfortunately, there is no HA integration at all for the Smartvest. It can only be paired with the SmartFriendsBox

Hence the idea of controlling these devices via the detour of the helpers (virtual switches) :wink:

I will report as soon as I could test it at home

Best regards

Hi,

i put a new " Virtueller Schalter" to my Box.

The RAW look like this:


{

    "id": 9029,

    "name": "Virtueller Schalter Test",

    "room": "Z test",

    "gatewayDevice": "SmartFriendsBox",

    "kind": "SwitchActuator",

    "manufacturer": "${Manufacturer.SmartHomePartner}",

    "state": 0,

    "devices": {

      "switchActuator": {

        "Id": 18630,

        "description": "VirtualInput",

        "commands": {

          "On": 1,

          "Off": 0

        },

        "currentValue": 0

      },

      "wallSwitch": {

        "Id": 17344,

        "description": "VirtualOutput",

        "currentValue": 0

      }

    }

  }

i try to put it in a switch like this, but is doesn´t work.


{

      "Id": 9029,

      "Type": "switch",

      "Parameters": {

          "icon": "mdi:toggle-switch",

          "state_on": 1,

          "state_off": 0,

          "payload_on": 1,

          "payload_off": 0,

          "assumed_state": true

      }

  }

I also tried it with just “state” or just “payload”, but that doesn’t change anything.

I can press the switch on the integrations, but it jumps back to off by itself after 2-3 seconds. And nothing reacts to the change.

The other problem is my Abus Smartvest window contact.


{

    "id": 14163,

    "name": "Fenster Heizung",

    "room": "5 Schlafzimmer",

    "gatewayDevice": "SmartFriendsBox",

    "kind": "DoorWindowContact",

    "manufacturer": "ABUS KG",

    "state": 1,

    "devices": {

      "doorWindowContact": {

        "Id": 18300,

        "description": "AbusDoorWindowNoc",

        "currentValue": 1

      },

      "failureStatus": {

        "Id": 4147,

        "description": "AbusFailureDevice",

        "currentValue": 0

      }

    }

  },

 

I’m just trying to get this to work in a very simple way.


{

    "Id": 14163,

    "Type": "binary_sensor",

    "Class": "door"

  },

which unfortunately didn’t work. It is always displayed as “unknown”. so I just tried it as with the switch, it is only displayed as open.


{

      "Id": 14163,

      "Type": "binary_sensor",

      "Class": "door",

      "Parameters": {

          "icon": "mdi:toggle-switch",

          "state_on": 1,

          "state_off": 0,

          "payload_on": 1,

          "payload_off": 0,

          "assumed_state": true

      }

  }

file

I hope you might have an idea how I can get the two to work. The virtual switch would be much more important to me :wink:

Many Thanks

You should try to see if you can control things using the REST api manually. Like you get the log in the browser, you can also do something like http://smartfriendsurl:5001/set/9029/switchActuator/1 If that doesn’t work then there is something wrong with the bridge. If it does work then its just the mapping. Sometimes I notice if you make changes to your deviceMap.json and restart the plugin HA still doesn’t pay attention to the changes. Manually delete the entity and restart the add-on again to see if the changes too place.

Hi everyone,
I have already written above with @GimpArm and have now again addressed my problem with the position of my shutters.
I use the Rest API for HA.
I can let my shutters up, down or stop, but unfortunately the position is not saved.

I have thought that the problem lies with the sensors for the individual shutters and have also found there. When I enter http://myip:5001/get/mydeviceid/position in the browser, nothing happens. The browser just sends me back to the start page.
Do you have a solution for this problem?

Many greetings,
Tom

I did not realize there was an open question here, I’m really sorry.

Not all Schellenberg blinds will report a position. If you do not see position listed when you do http://myip:5001/get/mydeviceid then this means it does not report position. First make sure you calibrated your blinds in the SmartFriends app, maybe even try removing them and re-adding them as I’ve found if you added on an earlier version there can be new features that get missed. Then restart the add-on and see if you get any new information. Removing the device will cause it’s ID to change, so make sure you re-configure for that.

If that does not work then the only other solution I can recommend is to make HA keep track of the position. There is an integration or add on or something that does this but I cannot remember what it is called.

Hello Tom_smarthome.
did you fixed the problem finally? I have the same problem….
My installation is a mix of the V2 (with integrated position sensor) and the previous schellenberg drives . Both are not showing either the value nor the „up“ command
br
Ole

Hi everyone! I’m considering this as a smartification of my currently dumb blinds, but am unsure - would I need a hub? Or does it work directly with Homeassistant if I have a working wifi and/or Zigbee network? I checked the addon itself and didn’t see a Readme file, and I browsed the comments but also didn’t see a clear answer because nobody seems to have asked the same question.

Edit: to clarify, due to the REST API I’m thinking it’ll be Homeassistant talking directly to the blinds via wifi, but I’d love to know before I spend money.

Hi @Olem_de,
I found no possible solution for that.

Hi @tinuthir ,
these AddOn is for the Smart Friends Box. With this box you can control for example your Schellenberg blinds which are communicating via a special radio. So you need an extra Gateway. Home Assistant “talk” via the REST API to that box and the box to the blinds.

For more information about that see: https://smart-friends.com

I hope my answer will help you.

1 Like

Immensely helpful, many kind thanks!

Sorry to bump this rather old thread.

Have used the Home Assistant Addon with a Smart Friends Box for a while now to control a Schellenberg Device (Markidrive) Everything was working excellent - both via REST and MQTT. However, apparently my Smart Friends Box and Phone App Auto-Updated (Android AppVersion now 3.4.4, Server API Version 3.3) and the addon is throwing the following error message during start since:

fail: SmartFriends.Api.Session[0]
      Refresh failed

Followed by an incredibly long json response and a failure reference to:

at SmartFriends.Api.Session.RefreshDevices() in D:\Projects\smartfriends-bridge\source\SmartFriends.Api\Session.cs:line 141

Naturally no devices are listed in the Rest Web Frontend ( just [ ] ).

Anybody else experienced this recently?