Skip to content

scs_bridge

krahabb edited this page Aug 30, 2021 · 4 revisions

The scs_bridge component allows EspHome to interface with BTicino/Legrand SCS bus. It provides raw send/receive of message frames for the bus in order to interact with all of the physical devices connected.

You can find a more or less detailed documentation of the bus protocol here thanks to GuidoPic which did all of the hard work. He also built different hardware and software implementations in order to integrate this bus into modern IoT environments but my work, beside the general protocol info he discovered, is not based on these implementations.

Actual implementation uses 2 GPIO lines to receive and transmit (the bus itself is an asynchronous serial protocol implementation similar to KNX). Once a frame is correctly received it can be forwarded to HA (sample config below) or processed in place. I don't have the 'big picture' of the protocol itself so I've just trial-errored my devices in order to get them work with HA. I only have roller-shutters and 2-wires video-doorbell tho in my BTicino setup so there's not much knowledge I can share. The covers are discovered and exposed to HA automatically so you don't have to play with device addresses in configuration.

The scs_bridge component, when booting, will try to auto-discover all bus devices with a broadcast query. Not sure if this is working for every device but, in case it works, it will automatically instantiate the discovered ones (only covers and switches right now...lights need some more thinking/work) Still this implementation might be raw/unstable, so, when you boot your ESP, it doesn't know of any device until it broadcasts some message on the bus (by just using it the physical way). I'm tyding up things in order to better manage this behaviour but, if your devices are not appearing in HA try to reload the esphome integration for the node so it 'refreshes' the HA entities. There is now support for statically configured covers and switches (example below) so you can explicitly set some general device configuration, 'stabilize' the discovery process and most important, for covers, set the time it takes to make a full run (by default my implementation uses 30 sec) so to have a better approximation of cover position.

Sample config

This is a basic yaml file for your esp node configuration. This will provide HA connection and expose a service (here named 'esphome.scs_bridge_scs_send') so you can send 'raw' frames to the bus. Received frames are also pushed back to HA through an event (here named 'esphome.scs_frame') containing the received frame. You can easily customize this behaviour by substuting any. This config will provide a 'full auto discovery' behaviour

substitutions:
  device_name: scs-bridge

esphome:
  name: $device_name
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable Home Assistant API
api:
  password: !secret api_password
  services:
    - service: scs_send
      variables:
        payload: string
        repeat: int
        acknowledge: bool
      then:
        - scs_bridge.send:
            payload: !lambda 'return payload;'
            repeat: !lambda 'return repeat;'
            acknowledge: !lambda 'return acknowledge;'

ota:
  password: !secret ota_password

scs_bridge:
  id: my_bridge
  rx_pin: GPIO4
  tx_pin: GPIO5
  device_name_template: '${device_name}_' # the discovered device hex addr will be added to this to set the entity name
  on_frame_received:
    - homeassistant.event:
        event: esphome.scs_frame
        data:
          payload: !lambda 'return payload;'

Once you know your devices address you can statically declare them. This way you can better customize the entity behaviour and add all of the EspHome goodies.

cover:
  - platform: scs_bridge
    name: '${device_name}_61'
    address: 0x61 # place the scs device bus address here
    max_duration: 21s # this is the full run time of the cover in order to estimate current position
    # you can add all of the standard cover config params here

switch:
  - platform: scs_bridge
    name: '${device_name}_10'
    address: 0x10 # place the scs device bus address here

Known Issues

I've implemented the acknowledge behaviour so, if a command is sent and doesn't rececive an ACK from the physical device, the node will try to resend the frame. Also, in this release, there's a 'collision detect' logic which will restart a frame send operation should it recognize the bus is busy while sending. These 2 features are not fully tested i.e. I've just tested they work when there is no collision and with proper acknowledge received. So this code should at least work not worse than the previous

Clone this wiki locally