s0 Output configuration

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

s0 Output configuration

#1 Post by Oetsch » 12 Oct 2022, 10:04

Hi

has anybody configured and ESP32 output as s0 output? Like to use the ESP32 with an PC817 to get s0 signals according power range received by mqtt.
I´m not sure how to generate s0 signals according spec 30ms< On <120ms & 30ms< Off

Is there sth. included in ESPeasy?

Thx

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#2 Post by TD-er » 12 Oct 2022, 10:43

You could send a "longpulse_ms" via the rules with 30 msec duration.
A longpulse does schedule its end, so it will not take less than 30 msec, but it might take more.
Since it is quite short, you may also use "pulse".
See: https://espeasy.readthedocs.io/en/lates ... ernal-gpio

The S0 only sends out a pulse when a new "mark" has been reached, like 1 Wh of energy measured.
So you can act on an event in the rules and then send a pulse command.

However the "pulse" command is blocking, where the "longpulse" isn't.
So if the measurement itself is timing critical, I would suggest going for the longpulse.
The only caveat here is that this is no guarantee the "down" level will be over 30 msec, nor that the next pulse will not start until the previous one has finished.
Perhaps we should extend the pulse (or longpulse) command with an extra duration so you can specify the up and down time.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#3 Post by Oetsch » 12 Oct 2022, 13:50

@TD-er

Big Thx. Just to be sure for myself. The command pulse/lonpulse will send a single High signal for a defined time. Not several pulses in the defined time, right?

Otherwise I question myself how long will theses several pulses be....how is this defined?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#4 Post by TD-er » 12 Oct 2022, 14:06

That's correct.
The "state" parameter determines the "on" value.
So you can easily invert the pulse if needed.
It will just send a single pulse.

Like I said, it will just act as a pulse you need to count.
Typically these are used on kWh meters, thus each pulse reflects a certain amount of energy (e.g. 1 Wh)
The time between pulses then reflects the actual power usage (Watt).
For example you counted 10 pulses in 1 minute, thus the power usage was then 10 Wh/minute => 600 Watt (as in at that rate it would have been 600 pulses in an hour = 600 Wh = 0.6 kWh)

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#5 Post by Oetsch » 12 Oct 2022, 16:10

Thx. Got it.

My intention is to submit wireless the current power surplus from a photovoltaic system to a heat pump (s0 Input).

So I´m in need to have "full control" of the pulse to submit the current power (Watt) by changing the timing (HIGH/Low). The input is configured for 500 pulses per kWh.

Not sure if its a good idea send the pulse event driven. Thinking about changing the pulse signal event driven and sending continously pulses. Guess Mqtt will be refereshed in fix cycles but it is not 100% bulletproof and also refreshments via Mqtt can get lost.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#6 Post by TD-er » 12 Oct 2022, 17:19

You could look at PWM.
But not sure if that's very useful for really low frequencies as you effectively need to set a really really low duty cycle.

Another trick you could use is still using longpulse_ms with 30 msec pulse and then a LoopTimerSet_ms to create an event whenever you need to send the next pulse.

As long as you don't call LoopTimerSet_ms again, it will continue.

So what you can do, is compute the desired interval between pulses and use that to set a looptimer.
When this needs to be updated, you compute a new interval and set it.

I would not update this too often as there will be a discrete error of course when switching to a new interval timer.
But once a minute would be fine I guess. (depending on your "load" of course)

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#7 Post by Oetsch » 12 Oct 2022, 18:06

Thx.
Thought a bit of the use case and it´s not expectable to get power above 7,2kW. In case of 500 pulses per kWh this means 7,2kW will have 1 pulse every second.

So running a loop continously every second:

on System#Boot do
LoopTimerSet,1,1
endon

on Rules#Timer=1 do
Let 1,%v1% + "mqtt-Power"/7.2
if %v1% >= 1
LongPulse_mS,XX,1,35
Let 1,0
endif
endon


what do you think?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#8 Post by TD-er » 13 Oct 2022, 00:10

I think you can go up way more ;)

See LoopTimerSet_ms https://espeasy.readthedocs.io/en/lates ... =looptimer

At minimum, you need 60 msec per pulse (30+ msec "up" and 30+ msec "down" as minimum)

So that's about 16x as much as absolute maximum for this S0 bus approach.

It is debateble if 16x per second running the LoopTimerSet_ms will be running fine as there may be some jitter.
I think 100 msec would be practically achievable, especially on ESP32 running the latest builds.
Still that's about 72 kWatt. I think that will be sufficient for most hoseholds :)

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#9 Post by Oetsch » 13 Oct 2022, 10:10

Big THX!

Very good to know that a ESP is capable of doing so. Afterwards I had the feeling that the error is to big because of loop time is close to the possible change time of the mqtt signal. But loop time 1/10 of mqtt time should be sufficent :)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#10 Post by TD-er » 13 Oct 2022, 10:31

Are you changing the value every second?
If so, then you may want to add some extra checks as you would otherwise end up with a pulse every second as minimum.

Now that I think of it, maybe it would be a great feature to have a command to alter the interval of a looptimer without resetting it.This way the "new" timer would then be scheduled based on the old scheduled timestamp.
Not sure if it should immediately reschedule the looptimer, or only on the next run. The latter option will of course introduce some delay when lowering the loop timer interval.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#11 Post by Oetsch » 13 Oct 2022, 11:46

For this case because some skripting is involved to get the power value and send it by mqtt it is updated every 3 seconds. But it would be nice, out of my view, to have a more general solution and I guess for mqtt a change every second is common, right? This would make it usable for other cases.

So I will use the 100ms loop and with this resolution (72kW) I do not expect a problem for a 10kWPeak photovoltaic system, right?
And at the end I guess the heat pump is only detecting if a defined level is reached or not. By reaching that level the pump is more often switched on because power is "cheap" and if not only switched on to fulfill very essential heating needs.


Have a rough idea what you are talking about with the feature of modification the loop timer. Wouldn´t it be more usable to have more features with regard to a signal generator inside of espeasy so that you can directly configure the signal to your needs ( event or cycle driven, frequency, fix or modifiable HIGH/LOW timing)?
But this is getting closer to a whish list for christmas so let´s deal with the possibilies we or better I have :)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#12 Post by TD-er » 13 Oct 2022, 12:15

Code: Select all

On myevent do    // Send some event with the new rate as argument, like myevent=1000 for 1000 Watt as desired output
  // Compute Watt to some pulse interval
  // 2 Watt = 1 pulse per hour (at 500 pulses per kWh)
  // Thus 1000 Watt = 500 pulses per hour = 7200 msec between pulses
  // Interval for %eventvalue1% Watt is 2*3600/%eventvalue1% seconds
  // Compute interval in msec: 2000*3600/%eventvalue1% = 7200000/%eventvalue1%
  let,1,7200000/%eventvalue1%
  looptimerset_ms,1,[int#1]  // Start loop timer 1, for computed interval
endon

On Rules#Timer=1 do
  LongPulse_mS,<GPIO>,1,30
endon
Something like this.
And it could also be extended using the current rules to allow to set the new timer without restarting the timer.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#13 Post by TD-er » 13 Oct 2022, 12:21

OK, I think this might work for updating the value without introducing lot of extra pulses:

Code: Select all

On myevent do    // Send some event with the new rate as argument, like myevent=1000 for 1000 Watt as desired output
  // Compute Watt to some pulse interval
  // 2 Watt = 1 pulse per hour (at 500 pulses per kWh)
  // Thus 1000 Watt = 500 pulses per hour = 7200 msec between pulses
  // Interval for %eventvalue1% Watt is 2*3600/%eventvalue1% seconds
  // Compute interval in msec: 2000*3600/%eventvalue1% = 7200000/%eventvalue1%
  let,1,7200000/%eventvalue1%
  
  if [int#2]=0
    // This is the first time we call this, so we 'bootstrap' the looptimer
	let,2,[int#1] // Copy the value, so we can later compare it to see if it has changed.
	looptimerset_ms,1,[int#2]  // Start loop timer 1, for computed interval  
  endif
endon

On Rules#Timer=1 do
  LongPulse_mS,<GPIO>,1,30
  if [int#2]!=[int#1]
	let,2,[int#1] // Copy the value, so we can later compare it to see if it has changed.
	looptimerset_ms,1,[int#2]  // restart loop timer 1, with updated interval
  endif  
endon
Drawback of this approach is that moving from a lower value to a higher value will take some time to be processed.
The delayed response time will be less when going from a higher value to a lower value.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#14 Post by TD-er » 13 Oct 2022, 12:56

Hmm thinking about this a bit more, I think this part should be slightly different when you experience 2 longpulses or one very short one.

Code: Select all

On Rules#Timer=1 do
  if [int#2]!=[int#1]
	let,2,[int#1] // Copy the value, so we can later compare it to see if it has changed.
	looptimerset_ms,1,[int#2]  // restart loop timer 1, with updated interval
  else
        LongPulse_mS,<GPIO>,1,30
  endif  
endon
It depends on whether the looptimer will be scheduled right away or continue on the existing schedule with the updated interval.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#15 Post by Oetsch » 15 Oct 2022, 09:24

Thx!
Now you got me and to go on I finally ordered my first very cheap test equipment.
Finding solutions is one point but to develop and check I need sth. beyond my very simple multimeter.

Looking forward to see the pulse coming out of the ESP and then come back. Now I haveto wait when our friends from oversea will deliver the package :)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#16 Post by TD-er » 15 Oct 2022, 13:28

Good news for you... I am now adding a new GPIO command.
wave_ms,GPIO,time_high,time_low,duraton

There will also be a version with all timings in usec.

So you only need to compute the period, subtract 30msec from it and you have a very accurate pulse.
For example you need to have a period of 7200 msec on GPIO-2, then you need to send a command like this:

wave_ms,2,30,7170

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#17 Post by Oetsch » 15 Oct 2022, 13:37

WOW, great NEWS! Big THANKS!

May I kindly ask where i can monitor if this new function ist available? Will it be announced as change in the release notes of a new mega release?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#18 Post by TD-er » 15 Oct 2022, 14:09

Right now, I'm testing it and find a way to also implement it on ESP32.
This seems to be one of the very few things that turn out to be easier on ESP8266 than on ESP32.
So if you plan to use it on ESP8266, I think I will move the ESP32 implementation to a later moment.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#19 Post by TD-er » 16 Oct 2022, 00:12

Decided to extend the options of the longpulse_ms command.
As soon as this PR is merged, it is included in ESPEasy. https://github.com/letscontrolit/ESPEasy/pull/4299

Or if you cannot wait, you can also try this test build, when it has finished: https://github.com/letscontrolit/ESPEas ... 3257343403

To send a continous pulse (the -1 option) to GPIO 2 with 30 msec high, (7200-30 = ) 7170 msec low:

Code: Select all

longpulse_ms,2,1,30,7170,-1

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#20 Post by Oetsch » 17 Oct 2022, 07:32

Thank you very much!

It´s not time critical because I´m also waiting for the optocoupler. Haven´t use on before connected to ESP but the datasheet says max. 50mA. This cannot be delivered by an ESP8266 so I decided to use ESP32 even if the current will not be max.

P.S.: One of your signature entrys is not working. Used the othe one ;) Thx!

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#21 Post by TD-er » 17 Oct 2022, 12:15

You will not need 50 mA for a LED in an optocoupler.
Very likely only need 5 - 20 mA. So you may need some resistor to limit the current anyway, but that's in this use case to protect the GPIO pin of the ESP.

I will again update the link in my signature, since that link expires quite quickly.

Oetsch
Normal user
Posts: 195
Joined: 13 Jul 2020, 12:10

Re: s0 Output configuration

#22 Post by Oetsch » 03 Feb 2023, 14:39

Thx. My new ordered "toy"/osciloscope was out of stock and now was delivered.

Your implementation works fine and looking great. THX!

Image

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#23 Post by TD-er » 03 Feb 2023, 14:56

Ah great!
And have fun with your new toy :)

mistral
New user
Posts: 2
Joined: 10 Dec 2023, 14:39

Re: s0 Output configuration

#24 Post by mistral » 10 Dec 2023, 14:53

How far are you?
I'm interested in exactly the same:
I have a HeatPump where the S0 signal from a electric meter could be connected where this electric meter would measure the energy provided back to the grid (i.e. the additional solar energy produced as currently needed). As I don't have such an electricity meter but as I have this information from the solar API, I have this information (about the additional kW currently produced). And thus, I would like to generate such an S0 signal with ESPHome. Additional advantage compared to the electric meter: I can e.g. add some margin (e.g. provide around 500 Watt lower energy to the heatpump to have some reserve for other devices being switched on etc.) or make this season dependent etc.
I would provide this information with HomeAssistant to ESPHome, but this would not change much.
I don't really have much ESPHome background yet, but I have a software developer background. Thus, I think I can also contribute. I hesitate more on the proper hardware wiring scheme as I'll only do this when I'm sure enough that it's safe for the HeatPump.
Thank you for your reply already!

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: s0 Output configuration

#25 Post by Ath » 10 Dec 2023, 15:04

mistral wrote: 10 Dec 2023, 14:53 I would provide this information with HomeAssistant to ESPHome, but this would not change much.
I don't really have much ESPHome background yet, but I have a software developer background.
Hi, this is the ESPEasy forum, not ESPHome, as you seem to assume?...

Or did I misunderstand your message?
/Ton (PayPal.me)

mistral
New user
Posts: 2
Joined: 10 Dec 2023, 14:39

Re: s0 Output configuration

#26 Post by mistral » 10 Dec 2023, 17:08

Ath wrote: 10 Dec 2023, 15:04
mistral wrote: 10 Dec 2023, 14:53 I would provide this information with HomeAssistant to ESPHome, but this would not change much.
I don't really have much ESPHome background yet, but I have a software developer background.
Hi, this is the ESPEasy forum, not ESPHome, as you seem to assume?...

Or did I misunderstand your message?
I just noticed my mistake as well, thank you. Please apologyze, I wasn't aware that this is something different so far.
But actually, I'm very flexible. If I can find a solution with ESPEasy and can transfer the required information (e.g. Energy information for the S0 signal) from Home Assistant to ESPEasy as well (maybe with MQTT), then this would also be a very good solution for me and I'll then try to get into ESPEasy as well.
I'm rather flexible on what I use for it as long as I can generate the correct S0 signal (right timing, right hardware) and the timing (for the correct S0 signal) based on energy information I would provide with home assistant (I could also calculate the timing in HA and pass this information to ESPEasy).

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: s0 Output configuration

#27 Post by TD-er » 10 Dec 2023, 17:45

ESPEasy does support MQTT.
You can publish data to MQTT, but also 'read' from MQTT via the MQTT import plugin.

Unless you have some very specific use case, I don't think encoding data via S0 is a good idea.
You still could do it, but it is far from accurate especially on low values and thus long intervals between pulses.

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests