Closed bigu1975 closed 3 years ago
Hi Bartoz,
Thanks for you report, based on your description it seems that the initial update is ignored. Could you comment out the following line (it shouldn't be there ... leftover from an older implementation):
https://github.com/jpcornil-git/HA-mcp23017/blob/main/custom_components/mcp23017/__init__.py#L366
You may also enable logging for this module in your configuration.yaml if the above doesn't fix the issue and report HA logs.
logger: default: warning logs: custom_components.mcp23017: debug
Cheers, jpc
I don't know what to say and how I can thank you. Indeed it makes the trick. Now works perfectly. There is a huge improvement in regards to "native" HA mcp23017 support.
Again thank you very, very much.
I would like to ask about one more thing. If I may... And I know is not an issue but rather ask for help in implementing change...
For my settings I need to quite different switch behavior. My target is to have following workflow for switches:
doesn't matter what I send to switch from HA - either On or Off I would like the switch together with pin will change its state to opposite. Even if the pin is low and status is Off when I send Off it will change the state to On and vice versa. For current mcp23017 HA implementation I have achieved it by the following changes in switch.py:
def turn_on(self, **kwargs): """Turn the device on.""" self._pin.value = not self._pin.value self._state = self.pin.value self.schedule_update_ha_state()
def turn_off(self, **kwargs): """Turn the device off.""" self._pin.value = not self._pin.value self._state = self.pin.value self.schedule_update_ha_state() Here I can't simply achieve it. I would be very grateful for support in this subject.
And Issue for switches. Again two mcp acting as switches. After fresh HA restart when I activate script to switch all switches on or off for both MCP, at the first time only first 8 outputs changes the state (pins from 0 to 7). After second time everything works for bot mcp.
Edit: Ok after fresh reboot pins from 0-7 are set to High, 8-15 as low on both MCP (invert_logic set to true). It is a problem wrong init (maybe).
For me the solution would be previous question in previous post. For other - not.
Thank you.
Hi Bartoz,,
Glad to see that the change solves your issue, I'll checkin the fix.
Wrt switch init behavior, I'm not sure I understand your description; after HA reboot the switch state shouldn't change, i.e. it should be the same as before the reboot (or mpc reset value), there is no reinitialization (if light/pump/... was on you want to keep everything as-is), see
https://github.com/jpcornil-git/HA-mcp23017/blob/main/custom_components/mcp23017/switch.py#L210
Note that a switch has a toggle primitive (https://www.home-assistant.io/integrations/switch/) => no need apriori to change the code ?
Cheers, jpc
Let's focus on init problem: My config:
platform: mcp23017 i2c_address: 0x20 invert_logic: true pins: 0: MCP 8 1: MCP 7 2: MCP 6 3: MCP 5 4: MCP 4 5: MCP 3 6: MCP 2 7: MCP 1
platform: mcp23017 i2c_address: 0x20 invert_logic: true pins: 8: MCP 15 9: MCP 14 10: MCP 13 11: MCP 12 12: MCP 11 13: MCP 10 14: MCP 9 15: MCP_NOTUSED1
platform: mcp23017 i2c_address: 0x21 invert_logic: true pins: 0: MCP 16 1: MCP 17 2: MCP 18 3: MCP 19 4: MCP 20 5: MCP 21 6: MCP 22 7: MCP 23
platform: mcp23017 i2c_address: 0x21 invert_logic: true pins: 8: MCP 24 9: MCP 25 10: MCP 26 11: MCP 27 12: MCP 28 13: MCP 29 14: MCP 30 15: MCP_NOTUSED2 All pins of are configured the same way. Let's assume I power on system. All switches should have the same status - On. But only first half of MCP have status On. Second half, all pins report: Off. And my assumption is that Off is only switch status but the real pin is set correctly as I need double action to have it synchronized again.
And you are right - after the HA restart switches keep its statuses but again only for register A (first half). Second half (register B) always shows off - and I know this is fake status - and only status. Real pin is set correctly
Hi Bartoz, Could you open another issue to track this one (I'll have a look in the mean time) Cheers jpc
It is done. Thank you - really.
Hello,
First of all I would like to thank you very much for your contribution. I have been searching such implementation since months. Finally I found it here. I have just tested it at HA core-2021.6.2 (the newest version). In overall I have attached 4 MCP23017 - two acts as Switches and 2 acts as Sensors. Switches works fine but I have huge problem with Sensors. I have manually installed your mod by adding mcp23017 directory to custom components HA folder (keeping the structure). Problem starts just after HA restart - when all inputs are LOW (without inverted logic with activated pull ups) for some pins HA shows incorrect status - HIGH. This happens every time (on every HA start/restart and always for the same pins). After playing with changing inputs HA reflects statuses changes and starts shows it correctly. Of course I need to change it twice to get correct status (it is related to wrongly set pins after restart). But... if the change only happens on the single pin it works great (for all pins). But If I am changing at once few pins (for instance I am connecting outputs from 2 first mcps as switches to inputs of sensors and via script I am changing statuses of all pins - HA for sensors are not reflecting changes on some pins. It happens on the same pins, which shows incorrect status after HA restart. Exactly the same settings works like a charm on default HA MCP23017 integration. I am using the following settings for sensors - and so far I remember at least one pin which have problem: pin6 on the first chip.
Thank you in advance for any help. This mcp implementation is far better. For me most important is lack of glitches during restarts.
Kind regards, Bartosz