GPIO outputs inverted

Hi there!

Is there a way to invert the GPIO outputs?

I have a 8 relay board which is controlled by 8 GPIO outputs and when I add the pins as output in Nymea, the relays are switched on. The powerstates in nymea are off.

Maybe this is a nice feature to add to the plugin?

Regards,

André

Hi there!

So, the upcoming release of nymea has some brand new generic IO support. The way that will work is that you can connect other “things” to GPIOs. For example, you have GPIO1 and connect a light thing to it. After that you’d see the light in nymea and when you toggle that light, it will in fact switch the GPIO1 behind the scenes. Those connections will also support inverting.

This is currently in the experimental repository and we hope to get it to the testing repository within the next days. From there it needs to pass some QA tests and once we don’t find any issues any more it will be released.

If you’re brave you are welcome to try things out on experimental and give us feedback.
However, keep in mind that you might hit bugs that require resetting the config, manually reinstalling packages (e.g. with some apt-get commands) or lose log history. So only do that on devices that are not critical for operation.

Also, please let me know which plugins exactly you are using and what kind of things you have connected to those relay switches so I can make sure all (or at least most) of your use cases will be covered when 0.21 comes out.

1 Like

Oh, I forgot, if you’re testing the experimental stuff, you’ll also have to install the beta of nymea:app in order to access the new GPIO goodness. On Android you can join the beta program in the Google Play store, or install the latest beta on Windows or MacOS from here: https://downloads.nymea.io/nymea-app/beta/ or switch to the edge channel if you’re running the Linux snap package.

1 Like

Ah great!

Well I can be brave, because I am building a whole new system for my pond. Now with nymea :wink:

For Nymea to work for my pond I am using the GPIO and One wire plugin. One wire for the temperature sensors (DS18B20) and GPIO to control the 8 relay board. Connected to the board are 8 outlets, so I can control the the pumps (water and air), uv light and my heater.

In the near future I want to connect some sensors for probing PH value and the water level.

I will test the new features and will give feedback where I can.

Regards,

André

1 Like

Alright. So after upgrading to experimental there will be a new plugin called “Generic things”. Install that and in there you’ll find a generic light, heating and irrigation things which can be connected to the GPIOs (assuming you are using the Raspberry Pi GPIO plugin).

I’ll have to add a generic thing for the air pump yet, will try to do so asap.

Check this README.md on how to set things up:

Edit: Standalone link without link preview to directly get to the README: https://github.com/nymea/nymea-plugins/pull/255/files#diff-1a72d29170bc18d53dda99e169b33c0d

1 Like

Hi Michael,

Tried the Generic Things and can install them, but I cannot find any setting for the GPIO settings.
Do I have to create a magic rule?

For me the Generic Power outlets are the ones to use, because my system will control the 8 power outlets in the casing via the 8ch relay board.

Edit: Forgot the beta nymea:app … :smiley:

Regards,

André

Work like a charm! Compliments!
This is exactly what I needed.

I can now control all the power sockets. I grouped the sockets to an always on group and a controlled group and will figure out how I can arrange that the always on group is turned on all the time (also after a reboot/power up).

Regards and keep you posted!

André

1 Like

For always on you could create a script like this:

ThingState {
    thingId: "...." // The ID of the thing you want to have on
    stateName: "power"
    value: true
}

That would turn it on after startup. Check the Scripting documentation here: https://docs-preview.nymea.io/docs/users/scripting/

You could even add a safety guard that would turn it back on after 5 minutes if for some reason it is turned off (e.g. manually turnign it off for cleaning the pond or something…).
With something like this:

ThingState {
    id: waterPump
    thingId: "...." // The ID of the thing you want to have on
    stateName: "power"
    value: true
}

Timer {
    interval: 1000 * 60 * 5
    running: waterPump.value === false
    onTriggered: waterPump.value = true
}

Maybe I’m wrong, but I think the inverted option for the GPIO’s are not set after a reboot.
All the 8 relays are turned on after a reboot. Can you verify this?

If you need some additional info please ask, so I can support you with that.

Regards,

André

1 Like

Nice! Thanks for the feedback. I’ll verify that.

Btw, if you update nymea:core and nymea:app now to the latest experimental (core) and beta (app), there will be a generic ventilation thing you can use for the air pump.

1 Like

This should be fixed now

Hi Michael,

Thanks for the update!

Did update my system and tested the new code.

Result: Software is ok: it show the two power sockets that must be on all the time, but on the 8ch relay all the power sockets are turned on, so the GPIO’s didn’t get a trigger to turn the relays off.

Maybe this is just a hardware problem, but I’m nt sure.

Regards,

André

Is the code different for the generic things? Otherwise I would suggest an option to change the icon of the generic thing, so you have less duplication in the code.

Regards,

André

It is the same code, and indeed duplicated… but it’s just one line, not really an issue… We may add support for changing icons eventually, however, it’s not just the icon… For example you can create rules to turn all ventilations at once. At that point we need the detailed information again anyways. Also you may have noticed that the ventilation device page icon rotates when it’s on… So this also allows us to customize each view properly for certain device types even though in the end they just toggle on/off…

1 Like

Hmm… doesn’t sound like a hardware issue… to investigate further I’d need some more information please:

  • What relay device exactly do you have? Please paste link.
  • Which generic thing do you have connected?
  • Is the connection inverted?
  • What exactly do you expect when starting the system up? (i.e. generic device on, GPIO off)
  • If you just power on the relay without having the GPIO connected at all, is it on or off?

(I know some of those are already answered above, but just to make sure that I don’t mix things up as we talked about different things throughout the thread please repeat for that particular “wrong” situation)

Hi Michael,

Below you find the requested information.

Type relay:

Generic thing connected:
Generic Power Socket (for now)

Inverted: Yes (all of them)

Expectations:
If the system is started up all “Generic Power Sockets” are off, except those that are setup as “Always on”. Meaning all GPIO’s should be off (right?).

What are the states of the relays when powerin the board:
All are off by default.

Hope this helps.

Regards,

André

Hi

Ok. I suppose you could connect the output differently too, so you a) wouldn’t need to logically invert them in software and b) wouldn’t have to rely so much on the Raspberry Pi at all. It would do the right thing even if the Raspberry Pi completely fails (e.g. SD card or power supply damaged or similar).

Nevertheless, the software still should do the right thing. So lets look at that:

I’m still confused a bit about your expectations. You say you expect the “Generic power sockets” to be off and also the ones GPIOs should be off. Yet they are inverted… Or do you mean only the GPIOs which are connected to the always-on Generic Power Sockets should be off?

Another thing I just notice: How nymea behaves right now is that it memorizes the last state on clean shutdowns… And that might actually already be the issue you’re seeing. I suppose when you power off your Raspberry Pi you just unplug the power cord. In that case nymea won’t store the current state and on the next start it will restore whatever state had been stored before… So if for example nymea restarted because of a system update it would store the sate and memorize that, If then later you only unplug it and replug it, it would restore that state it had on the system upgrade… I think that can be considered a bug in nymea… Will think about this more and perhaps change the code to store the last state immediately when it is changed instead of only during shutdown…

Ah ok.

What I mean is that the “Generic Power Sockets” should be off. Forget me mentioning the GPIO ones. Because of the value of the GPIO pins, the Generic Power Socket is turned on or off.

When I reboot the system I’m doing this by going to System Settings -> General and then choose restart nymea:core (so the nice way :wink: )

I think it would be preferable to save the state when something changes. For example in case of a power disruption this would result in the state it was before the disruption.

Oh by the way: My previous system just started up and left the GPIO pins untouched, so by default all relays were off. I used a python script to control everything. Now with nymea everything is much easier.

Hope my answers clearify the confusion.

Regards,

André

Hi André,

I have added a branch to experimental which would store the state right away when it changes instead of waiting for the shutdown. Originally I wanted to avoid that in order to be easier on the storage (e.g. flashes and SD-Cards wear off after some time with many write accesses) but now I think the benefit of it restoring properly in case of a power loss is bigger.

After the next experimental upgrade it should behave better. Not sure yet if I’ll include this in the 0.21 release still as it’s frozen already (although bugfixes still could go in).

1 Like