good afternoon YouTube so this video I wanted to look at a number of small changes that I've
made to my AC diversion load code over the last roughly two months previously I posted a video
where I added this damping code here and you probably saw the tail end of that the diversion
load was ramping down so this is a light dimmer that's controlling about a 600 watt heat lamp I
just turned on the dishwasher which uses about a kilowatt with that added low I'm now pumping 540
watts in on line two and then line one which is where the dishwasher is plugged into is using 1100
Watts total so that means my net power for the house is about 550 Watts so I'm supposed applying
roughly half the power to run the dishwasher from the hybrid inverter on my solar power system
yeah so here's my grafana graphing package running on home assistant and we can look at
the power or green is the total power and then yellow is line one blue is line two anything
below zero is power that's being pushed in and then anything above zero is basically a load so
the blue all here is all Excess power and you can see I was adding Excess power and then I had to
clamp the power down here because the load in the house dropped and then gradually here you
can see how the green line is down it goes up and then it it came down here to about 35 Watts here
and then right here I started up the dishwasher and you can see how the the blue there I was up
here at -177 watts and then just a while later I was at 5 41. you can see how that curve has
dropped down and then tapered off so I'm now pumping all available excess solar power into
running the dishwasher basically and then yeah I guess the dishwasher just kicked off it's probably
doing a rinse cycle the total power dropped and now it's stabilizing here around 25 to 35 Watts
set up the diversion load there and the power that I'm pumping in to the house now is only
180 watts and now you can see the dishwasher kicked back on and now this went from 44 22.
it's falling by half every 15 seconds so it'll take roughly a minute to get down to zero
and let's see if we can see that over here the grafana usually runs a little bit behind
but you can see right there we were at -550 if you look real close at the end
you can see how it dropped down and now it's coming back up but yeah let me show you some
of the changes I made so these changes were all related to this data here so this home
energy monitor that's the Hem this is the generation five home energy monitor from
aotech and the way this works is there's two current clamps clamp one is on line one clamp
two is on line two which are the two 120 volt halves of the 240 volt power feeding the house
and the way the meter works is it measures the current on line one it measures the current on
line two it's got a voltage sensing lead and it computes the total power on line one total
power on line two and then it adds the two up to get the total so then those three pieces of
data get reported back to the Vera plus home automation controller on the Z-Wave Network
so let me show you here this is what's called the status report from my P leg program logic
event generator solar power device here and with P leg you have what are known as triggers and I use
for instance this one here T below 25 the way that code is written it says whenever the power use for
the house drops below 25 watts and that happened today at 11 51 and and 37 seconds right there so
that was the last time that trigger went true and then down here I've got what are known as
schedules this is one change I made here I have two interval timers that run for 15 seconds so I
I have these two timers running they get started when the power drops below 25 watts and then I
have these two interval timers that I used to use self trigger timers but I've changed them to self
re-trigger timers because I want to keep them separate from each other they both start here
at 11 51 and 37 seconds but I have them start at staggered intervals and we can probably see that
here so clamp one timer started at 11 55 and 29 nine seconds so this was probably a few minutes
after the trigger I didn't catch it right at the instant clamp two actually started at 11 55 and 26
seconds so that's actually three seconds earlier so in that 15 second interval I wait three seconds
and then I start this timer and then three seconds later I start this timer so that I'm not doing
all of the checking and running code and updating devices and all that gets spread out over like six
seconds roughly and doing that I keep these timers separated in time and I'll show you how I do that
a little bit later here but then this was one of the key bits that I had to go back to one of the
p-leg features is you can set up what are called device properties and so for instance I have a
property I call call it the utility Watts property and it says get the value of Home energy Monitor
and get the energy metering or actually that's the Watts reading and what the program logic event
generator does is it takes the data from that device and puts it into this data structure called
a property I also do that for line two and line one power and then you can also see there's a last
change date this property looks like a variable but it actually has all of this information in
there and this property is actually an event so there was an event happened when this power
reading came in and you can then have other events like this trigger you create this trigger that
says hey when you read that power data in and if it goes below 25 Watts notify any conditions that
want to be notified of that event that it happened so here's the conditions this is where most of the
code lives I've did a couple things some more cleanup like I was using this synchronized code
multiple places so I just made separate conditions that just say it's during the daytime and then I
have this sequence that says the clamp one timer true and then it's false so that basically says
on the falling edge of that Interval Timer that's an event so the clamp two sink then Works off the
clamp to timer and so the idea is if I'm over here at 10 54 and I look at the data and I say hey that
data was updated three minutes ago it's probably not not current anymore and that's what I do here
in the code and then I have one check for line one power and another one for line two power so then
I have this condition here I call Energy meter quality where I just add up how many recent pieces
of data do I have and you can see here I have all three were current so I had three good pieces of
data it can be between zero and three and then I have this condition here if I see that the
energy meter quality is less than three meaning any piece of data is missing I request an update
so that's what this thing does is it just tries to keep pinging the power meter and send me new
data yeah let's go back here uh think back here there's some examples of this so one thing I found
as I dug deeper into this these blank spots are obvious there's no data there but look right here
I have line two I have line one there's line two and one two and one one thing I did with that was
I realized if I have two pieces of data I can reconstruct the missing third piece so I come
in here and I say hey if the total power is old but I know the line one power and the line two
power are current then add line one plus line two and that's the total if the current value
is current then just use it directly and I do that for all three and then down here I also
found there are cases where line one plus line two does not equal the total I do a Sandy check
here that's within 10 watts of being correct I'll accept it if it's outside of the that value I'll
throw it away and then I have this condition here that I just call Energy meter data stale
so I'm basically saying if I know fewer than two pieces of data I don't know what's going on so I
use that later in the code here those were all the things I added here to clean up the
data so that's what all of this stuff was for is basically conditioning sanity checking the
data reconstructing it if it's missing it wasn't really bugs in the code that I was fixing it was
bugs in the data that I was getting and I had to protect my code from Bad data like the saying goes
garbage in garbage out so I'm trying to keep the garbage out so I mentioned how I had changed to
the self re-trigger timer and so I added this code here to only start up one time per day
and the way it works is kind of a weird looking code if you read it so it basically says the
startup diversion load to condition requires these three things in order or in sequence and the first
thing it requires is this has to be true well it's false right now so if you look at it this thing
will never start right because it's it's false the way it works is once it goes false it will
be false until tomorrow so the way I do that is with this daytime schedule so this daytime turned
on sometime after sunrise this morning so this started at 6 39 this morning and if we go down
here this thing was true at 11 51 but this thing was true before that at 6 39 this sequence won't
happen again today a because this thing happened after that thing and the way this code reads this
is a sequence of things in time so you have to have that true and then that true and then that
true at some time in the past so the way this will work tomorrow morning is this was true today at 11
51 and then tomorrow at about 6 40 in the morning this thing will be true and then sometime around
noon tomorrow this will go below 25 watts and this event will happen and then this thing will set
true for one interval 15 seconds it's true and then it goes false again and then otherwise if
I don't start the timer I just restart the timer every 15 seconds the timer runs so that's how the
timers work they just start up and then it either just spin ends here as the restart restart restart
all day long and then the rest of the code checks if I need to do anything this is where I compute
the watts per step I showed you how I did that before except the the change I'm doing now is
I'm using my computed line 2 power in case I had to reconstruct the data if it was missing and I
compute a setting for the light dimmer 6.8 percent and then this one here the sharing code is where
I added some protection here I've had problems with commenting the code in P leg every once in
a while it decides I don't like comments anymore and it just throws them all away you get one line
comment and one line of code so what I've done is I've brought some of those pieces of code into
notepad plus plus so here's the this diversion load to share code which is this I brought it
in here and written it more like pseudo code I can add more comments and split the code up so
I can see what's going on it looks a lot more like a normal programming language that variable equals
this bunch of code and so I checked that I've had the whole house diversion load feature enabled and
then the energy meter quality do I know at least two pieces of data and does the data make sense I
also say is the diversion load on line one ah because I don't want to be sending power from
line 2 over to line one only to have the diversion load on line one eat up the power and so that's
that code I basically say all these things have to be true and then I say a if there's excess load
on line one so I take the power on line one and see if that's greater than my target power so for
example if I had 200 watts of load on line one and my target power here is 25 watts I have 25 minus
200 is minus 175 so I've got 175 watts of excess load on line one that I can use to eat up Excess
power on line two and then otherwise I return zero and if any of these are false I don't want
to do anything so I return a 0 there so that's the way that code works it's pretty simple it looks a
little messy because you have to do it all on one line and then here is where I also made a
change to protect the code so one thing I do is I say only get here after the clamp
two timer has timed out so I don't want to do this computation until I'm ready to do something about
it and then I check the energy meter quality is the data believable and then I check is the
new setting different than the old setting and if it is then I set this thing true and
then I have basically the same code down here for diversion load one anyway that is my updated codes
yeah if you have any questions about that post
up in the comment section below and as always thanks for watching