Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Relay's #1375

Closed
proddy opened this issue Oct 31, 2023 · 25 comments
Closed

Support for Relay's #1375

proddy opened this issue Oct 31, 2023 · 25 comments
Labels
enhancement New feature or request
Milestone

Comments

@proddy
Copy link
Contributor

proddy commented Oct 31, 2023

New feature to handle Relay's attached to GPIOs.

  • We can use the existing Analog Sensors 'Digital Out' with value 0 (off) or 1 (on)
  • The Analog Sensors should be renamed to something like 'Board I/O' as technically they are not all sensors. This would be a breaking change as the MQTT topic 'analogsensor' would be renamed. We can handle this in the auto-upgrade code but it will break existing HA/ioBroker connections.
  • Ensure Digital Out's are executed on EMS-ESP startup. Now it will send 0 and switch off any relays?

@MichaelDvP I am missing anything?

@proddy proddy added the enhancement New feature or request label Oct 31, 2023
@proddy proddy added this to the v3.7.0 milestone Oct 31, 2023
@MichaelDvP
Copy link
Contributor

Ensure Digital Out's are executed on EMS-ESP startup. Now it will send 0 and switch off any relays?

No, it always stores the state in filesystem and sets it on boot. Make sure the pin is output and not used by board profile.

@bbqkees
Copy link
Contributor

bbqkees commented Nov 1, 2023

For relay boards you have active low and active high relays.
So that would need to be a setting. For active low ones sending a 0 will turn ON the relay.
And it's nice if you can give the user the option for relays to either go OFF when rebooted/power out or that they maintain their last state.

@MichaelDvP
Copy link
Contributor

Ensure Digital Out's are executed on EMS-ESP startup. Now it will send 0 and switch off any relays?

No, it always stores the state in filesystem and sets it on boot. Make sure the pin is output and not used by board profile.

Ups, it's stored when changing via web, it's not stored on changes via api/mqtt. Has to be fixed.

@MichaelDvP
Copy link
Contributor

For relay boards you have active low and active high relays.
So that would need to be a setting. For active low ones sending a 0 will turn ON the relay.
And it's nice if you can give the user the option for relays to either go OFF when rebooted/power out or that they maintain their last state.

Something like that?
grafik

@proddy
Copy link
Contributor Author

proddy commented Nov 1, 2023

yes, perfect. Just upper case the strings

MichaelDvP added a commit to MichaelDvP/EMS-ESP32 that referenced this issue Nov 2, 2023
@MichaelDvP
Copy link
Contributor

Ok, i have integrated the function in my test(dev2) build. Should i make a PR or do you like to test first?
I have not changed the names for now, only set all strings with "analogsensor" to F_(analogsensor) to change the name quickly in local_common file. In web-i18 there are still a lot of analogsnensor related names to be translated.

@hetii
Copy link

hetii commented Nov 3, 2023

Hey :)

What about input support?

As I plan to design my own hardware I would like to use more GPIOs of esp32 for few inputs/outputs role.

About outputs, it also be nice to see some basic cronjobs syntax support, eg for stuff like enabling hot water circulation pump every day starting from 6am till 10pm for five minutes every two hours, for those who don't plan to use HA for it.

Regards.

@bbqkees
Copy link
Contributor

bbqkees commented Nov 3, 2023 via email

@proddy
Copy link
Contributor Author

proddy commented Nov 4, 2023

Ok, i have integrated the function in my test(dev2) build. Should i make a PR or do you like to test first? I have not changed the names for now, only set all strings with "analogsensor" to F_(analogsensor) to change the name quickly in local_common file. In web-i18 there are still a lot of analogsnensor related names to be translated.

@MichaelDvP I'm sure it's great, just PR and push into dev2. Do you think we should rename analogsensors at some point?

@masterx1981
Copy link

This would be very nice to have! As by now seem that "virtually" turning on the inputs isn't working (#1388) i'll use a relay for turning on the smart grid i4 input.
The gpio output are enough for driving directly a small relay like the omron g5v-2 5dc (100ma), or the high sensitivity g5v-2 h1 5vdc (30ma)? Or in any case maybe it's better to use an npn as driver (plus eventually the flyback recirculation diode)?

@MichaelDvP
Copy link
Contributor

  • Turning the inputs by setting invert should work, see read and write inputs of heatpump #600 (comment)
  • you can't drive a 5V releais from 3.3V SOC. Also the esp32 can sink max. 28 mA and source 20 mA per port (28/40 mA for some ports if used single),
  • the 3.3 V regulator on most boards can not source an additional relais

@masterx1981
Copy link

Whops, forgot the 3.3v thing, and also there aren't a lot of 3.3v relais, in any case would be nice to have this feature, there are out a lot of ready made relays modules with integrated driver...
The problem that i see using the hp1inopt swap bit mode, is that my heat pump hp1~hp4 in opt never change, whatever is the state of the phisical inputs. Or the hp1inopt input is the "logic" of the input (active high/active low) of the signal? This evening i'll check this out. Sorry for the off topic...

@bbqkees
Copy link
Contributor

bbqkees commented Nov 27, 2023

@masterx1981 You can already switch physical relays with EMS-ESP.
Via Add Analog Sensor -> type Output.
We just want to make it more logical and and more convenient to use in the web interface.

If you want to make use of a relay currently the best way to do it is to use a ready made board with optocoupler inputs and an external power supply for the relay board. (Preferably with higher quality relays like Omron or Panasonic.)
This way it cannot really interfere on the EMS bus.
In your case you just want to switch a low-voltage input/dry contact of the heat pump, that is relatively safe to do.
But others try to switch heavy loads on mains power. If not done properly this can be dangerous for the boiler/heat pump and the person itself.

For some safety guidelines for everyone check here: https://bbqkees-electronics.nl/wiki/gateway/using-gateway-gpio.html

Furthermore I do not support switching relays from a BBQKees Gateway. But if you do it anyway, use an external power supply for the relays. When connected via the service jack the power to run the Gateway flows back through components of the EMS circuit. Those are designed to carry the load of the Gateway itself (with a bit of head room of course) but NOT additional power hungry relays.
If the Gateway is powered via the 12V DC input more current can be drawn safely as the return path for the current is not via the EMS circuit. But with recent Gateways you only have 3,3V available so you need an external power supply for the relays anyway.

@proddy proddy modified the milestones: v3.7.0, v3.6.5 Feb 3, 2024
@proddy
Copy link
Contributor Author

proddy commented Feb 3, 2024

3.6.5 support this and I've updated the documentaton.

@proddy proddy closed this as completed Feb 3, 2024
@suaveolent
Copy link
Contributor

@proddy i habe been playing around wither the feature yesterday. It works great so far.
However, it only works for Active High for me, which unfortunately has the relay state inverted.

If I set it to Active-Low the relay does not switch at all.
Am i doing anything wrong here?

@proddy
Copy link
Contributor Author

proddy commented Oct 8, 2024

This could be how the offset is handled in the code. I'll see if I can reproduce it. Can you tell me

  • which EMS-ESP version you are using
  • which GPIO pin is the relay controlling

I also noticed some fixes needed in the web UI, so I'll do those too!

@proddy proddy reopened this Oct 8, 2024
@suaveolent
Copy link
Contributor

Thanks, the issue occurred on 3.6.5 as well as latest 3.7.0.

Im using a Lolin S3 and pins 47/48. (it is a 2 way relay module).

I could reproduce it, however, on other pins too.

@MichaelDvP
Copy link
Contributor

There is a bug in setting the pin in analogsensor.cpp, line 213
set this to:
digitalWrite(sensor.gpio(), (sensor.offset() == 0) ^ (sensor.factor() != 0));

@proddy
Copy link
Contributor Author

proddy commented Oct 9, 2024

yeah, I saw that. Its on the fix list for my next PR (ft_dashboard branch)

@proddy
Copy link
Contributor Author

proddy commented Oct 9, 2024

and line 759 with the command_setvalue() ?

@proddy
Copy link
Contributor Author

proddy commented Oct 10, 2024

fixed in ft_dashboard branch, probably 3.7.0-dev.44

@proddy proddy closed this as completed Oct 10, 2024
@suaveolent
Copy link
Contributor

@proddy thanks for the fast fix. The relays now also switch when set to "Active low". Unfortunately, they now behave the same as "Active high".

@MichaelDvP
Copy link
Contributor

Ups, Active low is stored as factor -1 in web (not 0 as i thought), so the switch should be:
digitalWrite(sensor.gpio(), (sensor.offset() == 0) ^ (sensor.factor() > 0));

@proddy
Copy link
Contributor Author

proddy commented Oct 14, 2024

Fixed in 3.7.0-dev.45

@suaveolent
Copy link
Contributor

Thanks, its working now! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants