Redefining the on/off switch thing

I am working on a home automation project focused around using the GPIO add-on to drive a relay board. Is there a way to redefine the “on” state of the on/off switch thing to be low rather than high?
Unfortunately, the GUI defined “on” state of the on/off switch thing is when the GPIO pin goes High. The relay board I am using is active when low, which results in reversed logic on the GUI - the on/off switch reports “ON” while the relay board is actually in an “off” state.
I would remedy this simply by changing my wiring on the relay to the other pole, however, this will cause problems for the power loss failsafe condition. In the case of RP power loss, all relays would default to the on position; obviously this is a safety concern since it will activate all attached equipment, assuming it has power.
I have worked around this problem by defining virtual on/off switches and making rules that tie them to the opposite logic of their corresponding GPIO on/off things. When the Virtual switch thing is on, the GPIO on/off switch is off and vice versa. This works fine, except that I now have a large amount of GUI on/off switch things (virtual and GPIO) and there seems to be a limit to how many virtual on/off switches I can create. I am up to eight now, and I can no longer “add” more as virtual on/off switch it is not present in the add things menu.
Any ideas?

That can be handled in your code. i did something similar in my python webthing that was detecting the state of an input. It was “on” when the physical object was closed. I had to make the code reverse that:

    if new_state == 1:
        corrected_state = 0
    elif new_state == 0:
        corrected_state = 1

Then read off the corrected_state.

Currently, there isn’t a way, but I just filed a bug to add an “activeLow” configuration item. When the gpio adapter was first written, we didn’t have the ability to provide per-pin configuration.

I’m sorry. I completely overlooked your reference to the GPIO add-on. So, as noted above, there isn’t currently a way to do what you’re asking… using the GPIO adapter. That’s basicslly why I ended up building my own Python webthing. You can take a look at that, but it’s more involved than just using the GPIO add-on. On the upside, you can add as many things as you might need when you build it yourself based on the webthing implementation. IMO, it’s worth considering it.

Thanks very much Dave. You mention there was no per-pin config available at the time of adapter writing… can the entire gpio adapter be configured as active low? This is the only thing Im using the gpio adapter for, so in my particular case, I don’t mind not having individual pin configurability. Thanks again.

No worries, Kevin - thanks for the info. Coding isn’t my strong suit, thus why the drag-and-drop gateway GUI is attractive to me. I’d need some serious hand holding to figure out how to begin exploring your python webthing. How can I go about adding it to my gateway? Thanks again.

Coding is definitely required, but you can probably figure it out. You can start looking at https://github.com/mozilla-iot They have tons of details, documentation, and links to webthings in java, python, node, and others. The webthing pages have installation instructions and examples on how the code lays out. I thought python would be one of the easier ones, and one of the other items I was tying into was written in python, as well. So, it served me to learn a bit of python. From there, I added webthing via python pip (already installed if you used the Mozilla IoT Gateway base image), and added my one page of code to read a sensor and give it trigger abilities for a relay. Once it was running, it immediately showed on the add things screen of my gateway. You’ll also need to learn a bit about GPIO controls, but that’s often learned using python, as well. Those can be found at https://sunfounder.com or https://learn.adafruit.com or all over YouTube. If nothing else, it’ll be a fun adventure. Then again, I may have a distorted view of what “fun” is.

I really appreciate all the advice… I’ll give it a go and see if I can make it work. Thanks again.