Invert input reading on Automation Hat


as found here

I have connected Automation Hat 5V to Input 1 and the reading is 1. Just fine.

I would like to reverse it, i.e. to get 0 when 5V is connected to Input 1 and vice versa.

How can I do that? Please advise.

Not meaning to a smart @ss, but one has to ask why? What are you coding in? And or wanting to do?

I have to invert the reading of a opening sensor for Homebridge/Homekit.

sensor open -> gate closed
sensor closed -> gate open or opening.

How can I do that?

Change your code to
sensor closed -> gate closed
sensor open -> gate open or opening.

Better yet, please post your code. On my keyboard I have a key in the top left with a ~ and a under it. Three then your code and three more` will retain the syntax and indents.

There is no code to post, I use Homebridge and HomeKit and I can not modify them.

I need to do this via hardware

Ok, that explains that. I have to give that some thought?

One of these may work,
Or a 5V relay. You have the +5V turn the relay or opto isolator on and wire it so it sends a ground / short.

1 Like

You could use an NPN transistor and pull-up resistor to form a simple inverter circuit, in theory.

The accepted answer here explains it better than I could:

1 Like