jpcornil-git / HA-mcp23017

MCP23017 implementation for Home Assistant (threadsafe, lower latency and config flow support)
17 stars 6 forks source link

why every time raspberry Pi4 power on, all switch will ALL ON? #24

Closed hzkincony closed 3 months ago

hzkincony commented 3 months ago

Hello, thanks for your add-on. now i use these config code, every time when home assistant start up, all switch will ALL ON. can you tell me , how to let all switch output ALL OFF or don't change state when home assistant reboot. switch:

jpcornil-git commented 3 months ago

If mcp23017 is not reset by your hardware or by a power cycle, switch states shouldn't change given your configuration.

hw_sync parameter is indeed not defined and therefore set to True (default value); this means that the integration should read mcp23017 states when HA starts up for these entities.

I guess that when HA starts up, your mcp23017 hardware is also reset somehow and therefore outputs reset to their default values, i.e. 0 (ON with invert_logic set to True).

Could you describe your hardware and what do you mean exactly with "home assistant start up" ?

hzkincony commented 3 months ago

here the pdf is diagram of MCP23017 circuit. CM4 i2c bus connect with MCP23017 -> 74HCT14 -> ULN2003 -> RELAY "home assistant start up" means: power ON of raspberry pi4 do you means, i should add: "hw_sync: true " and set "invert_logic: false" ? Thanks for your help. inout_V1.2.pdf

jpcornil-git commented 3 months ago

Thanks for the schematic, is the 3V3 used by the mcp23017 supplied from CM4's CM4_3.3V (Output) (pin 84 & 86 see p20 of CM4 datasheet) ?

If it is the case, then 3V3 goes down during a power cycle if I read correctly.

I guess that if you just restart HA (but not CM4) then output levels are preserved ?

hzkincony commented 3 months ago
  1. 3V3 used by the mcp23017 supplied from CM4's CM4_3.3V (Output) --> NO, not connected directly. CM4 use by 5v power.

  2. i power off and on of DC12v power supply, so when power off, CM4 and MCP23017 both no power. my CM4 and MCP23017 build in one PCB.

jpcornil-git commented 3 months ago

If mcp23017 loose its power then related states are also lost, i.e. when everything restart you get power on reset default states (OFF with invert_logic=False ON otherwise).

Note that if you use config flow rather than yaml to configure a mcp23017 then you can set invert_logic per entity rather than per device (with yaml you can change it using the UI but it is not persistent).

hzkincony commented 3 months ago

if i set "invert_logic=False" , when power on of PCB, all relay also will all ON, just home assitant UI switch state exchanged. do you think it's hardware circuit problem?

jpcornil-git commented 3 months ago

It is not a hardware issue but the expected behavior; mcp23017 sets its output registers to 0 after reset/power up, invert_logic only affects HA state/how you see it.

hzkincony commented 3 months ago

i sloved, just need add "hw_sync: false" will be ok. thank you very much for your help. we will make new pcb with 4pcs of MCP23017, 32 channel binary sensor + 32 channel switch. your component support that , OK?

jpcornil-git commented 3 months ago

hw_sync=False will force output to OFF at power up from a UI/HA perspective (for mcp23017 this is 0 with invert_logic=False, 1 otherwise).

No issues with support for multiples mcp23017 devices as long as they are on the same i2c bus.

hzkincony commented 3 months ago

OK, thanks again.