Cover and MCP23017

Hi.
I want to control a garage door with HA. I see the gpio module alreay does that with the cover module.

I mounted a MCP23017 chip on an expansion board (example python managing software here) connected via i2c. I see for managing i2c I need to use the binary_sensor module, but I don’t understand how this latest works with the rest of the system.

Should I configure the binary sensors for enabling the i2c, and then use the PINs from the binary config for cover?

Should I use i2c_gpio?

Thanks

There’s an integration for MCP23017

Yeah I found it, I forgot to link it. But then I have a switch… While I need cover.

Then you can use the Template cover to call your switches, or to call scripts that turn them on/off.

I’m trying to figure out how it works but I’m new to HA and have close-to-zero knowledge of electronics. :frowning:

I’ve enabled the i2c stuff on the system, and I can detect the chip:

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- 27 -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

So I assume i2c address is 0x27.

The chip has two series of port, for input and output. I’ve configured ha this way:

binary_sensor:
  - platform: mcp23017
    i2c_address: 0x27
    scan_interval: 2
    pins:
      1: garage_door

switch:
  - platform: mcp23017
    i2c_address: 0x27
    pins:
      15: Garage Switch

so that I can detect the state via the sensor and control the door via the switch.

First weird thing happening: my expansion board has LEDs showing the state of the pins. With the wrong (default) 0x20 i2c address I can see the input status led turning on and off. Now that I’ve entered 0x27 the input led is always on. I can only see a very little intensity change when I change the switch status on HA interface (which is still weird because that should control the output pins, while this is an input one!).

Other than this, which is probably and hardware issue I’m failing to understand, there’s the template config. The example uses i.e. switch.garage_door, but I don’t get where this is configured. In the switch configuration I see you can set pin numbers and configuration names, but those can contain spaces and doesn’t seem to fit there.

Any hint is welcome :sweat_smile:. Thanks

Managed to sort out the configuration.

Final config is this:

binary_sensor:
  - platform: mcp23017
    i2c_address: 0x27
    invert_logic: true
    scan_interval: 2
    pins:
      15: garage_door_15
 
switch:
  - platform: mcp23017
    i2c_address: 0x27
    pins:
      0: Garage Switch
cover:
  - platform: template
    covers:
      garage_door:
        friendly_name: "Garage Door tpl"
        value_template: "{{ states('binary_sensor.garage_door_15') == 'off' }}"
        stop_cover:
          service: script.1566942782554
        open_cover:
          service: script.1566942782554
        close_cover:
          service: script.1566942782554

with the following script:

'1566942782554':
  alias: Bottone garage
  sequence:
  - data:
      entity_id: switch.garage_switch
    service: switch.turn_on
  - delay:
      milliseconds: 100
  - data:
      entity_id: switch.garage_switch
    service: switch.turn_off

Full detail here.

2 Likes