emsesp / EMS-ESP32

ESP32 firmware to read and control EMS and Heatronic compatible equipment such as boilers, thermostats, solar modules, and heat pumps
https://emsesp.github.io/docs
GNU Lesser General Public License v3.0
628 stars 107 forks source link

Support for Relay's #1375

Closed proddy closed 1 month ago

proddy commented 1 year ago

New feature to handle Relay's attached to GPIOs.

@MichaelDvP I am missing anything?

MichaelDvP commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

yes, perfect. Just upper case the strings

MichaelDvP commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

There is already a scheduler in the firmware and several types of inputs are also available in the Sensors section.

On Fri, 3 Nov 2023, 19:04 hetii, @.***> wrote:

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 ho don't plan to use HA for it.

Regards.

— Reply to this email directly, view it on GitHub https://github.com/emsesp/EMS-ESP32/issues/1375#issuecomment-1792901687, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSGZAWU4KCDU5FKJI65Z4LYCUWY7AVCNFSM6AAAAAA6YKBVKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJSHEYDCNRYG4 . You are receiving this because you commented.Message ID: @.***>

proddy commented 1 year ago

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 commented 11 months ago

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 commented 11 months ago
masterx1981 commented 11 months ago

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 commented 11 months ago

@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 commented 9 months ago

3.6.5 support this and I've updated the documentaton.

suaveolent commented 1 month ago

@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 commented 1 month ago

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

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

suaveolent commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

proddy commented 1 month ago

and line 759 with the command_setvalue() ?

proddy commented 1 month ago

fixed in ft_dashboard branch, probably 3.7.0-dev.44

suaveolent commented 1 month ago

@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 commented 1 month ago

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 commented 1 month ago

Fixed in 3.7.0-dev.45

suaveolent commented 1 month ago

Thanks, its working now! 🚀