Sumarize minutes a DI was true last 24h

9 years 3 days ago #2697 by Ruettimann
Hi there
Friend of mine has a Solar Panel (about 70 kw/h) which gives me a Virtual DI (call it POWER), when it is running on 50% ore more.
When I get this signal, I switch some consumers (water heating) via ethernet, works great.
Now Problem is:
- If I got 180 minutes or more during a day, I do not need to switch the consumers (water heating) from 22:00 til 06:00
- If I got less than 180 minutes during a day, I need to turn the consumers on at night.

Does anyone have a idea how to calculate this?

Of course I can do this on bash by raspberry pi, but that is ugly! B)

I tried:
1- To create a Virtual DI and increment its value (when POWER is ture) by cron (every minute)
but I was not able to write the value back to virtual DI, it is asking for string, but I have double and can not convert.
I also do not understand why to write a Value to DI in string fromat?
2- Use a Variable, but I do not now, how to make my counter "global" so that it can increment its value every minute when cron is running:
public void Setup(){
}
public void Run(){
  int ism;
  ModuleParameter s = ModuleHelper.GetProperty(Domains.VIRTUAL, "N2S0", "Sensor.DigitalValue");
  if (s.Value  == "1"){
    if (ism <= 0 || ism >=6000 ){ism = 0;}
    ism = ism + 1;
    Console.WriteLine("sunshine=" + s.Value);
    Console.WriteLine("sunshine_minutes=" + ism);
    }
} 

I would prefere to get variant 1 running, because I would be able to write a graph with "daily sunshine minutes"

Help is highly welcome!
Chris

PS: I woud write down a howto about the entire solustion into this forum when it is running, hopefully others can use it also.

Please Log in or Create an account to join the conversation.

9 years 2 days ago #2700 by Ruettimann
I found a solution by converting Values to integer and back to string.
It seems to work, but sadly, cron is broken on raspberry pi.
so I can't use my solution :( :
public void Setup(){
}

public void Run(){
  // Console.WriteLine("Run");
  ModuleParameter s = ModuleHelper.GetProperty(Domains.VIRTUAL, "N2S0", "Sensor.DigitalValue");
  ModuleParameter sm = ModuleHelper.GetProperty(Domains.VIRTUAL, "N5S0", "Sensor.AnalogValue");
  if (s.Value  == "1"){
    //Console.WriteLine("sunshine=" + s.Value);
    int tsm = Int32.Parse(sm.Value);
    tsm = tsm + 10;
    //Console.WriteLine("out=" + tsm);
    DriverHelper.ProcessCommad(Domains.VIRTUAL, "N5S0", "ControlLevel", tsm.ToString());
  }
} 

Please Log in or Create an account to join the conversation.

8 years 11 months ago - 8 years 11 months ago #2715 by Ruettimann
Hi, I found a solution
Not sure if it is elegant, but it works like a charme!

This are the Sensors/Switches:
string SOLAR_OVERFLOW_WANTED_DAILY = "N1S0";
string SOLAR_OVERFLOW_SENSOR = "N2S0";
string SOLAR_OVERFLOW_CONSUMER1 = "N3S0";
string SOLAR_OVERFLOW_CONSUMER2 = "N4S0";
string SOLAR_OVERFLOW_DAILY_MINUTES = "N5S0";

Here are my automation scripts:

Program name: control overfolw consumer devices
Cron Settings: (empty)
public void Setup() 
{ 
  //string SOLAR_OVERFLOW_WANTED_DAILY  = "N1S0";
  string SOLAR_OVERFLOW_SENSOR        = "N2S0";
  string SOLAR_OVERFLOW_CONSUMER1     = "N3S0";
  string SOLAR_OVERFLOW_CONSUMER2     = "N4S0";
  //string SOLAR_OVERFLOW_DAILY_MINUTES = "N5S0";
  EventHelper.ModuleChangedHandler((o, m, p) => 
  {  
    // filter digital switch - change module address 
    if (m.Domain == Domains.VIRTUAL && m.Address == SOLAR_OVERFLOW_SENSOR && p.Property == "Sensor.DigitalValue"){ 
      // filter when switch on event  
      if (p.Value == "1") 
      { 
        DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER1, "ControlOn", "");       
        DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER2, "ControlOn", "");       
      } else {
        DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER1, "ControlOff", "");       
        DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER2, "ControlOff", "");     
      }
    } 
    return true;  
  });  
} 
public void Run() 
{ 
}

Program name: calculate daily minutes of overflow
Cron Settings: * * * * *
public void Setup(){
}

public void Run(){
  //string SOLAR_OVERFLOW_WANTED_DAILY  = "N1S0";
  string SOLAR_OVERFLOW_SENSOR        = "N2S0";
  //string SOLAR_OVERFLOW_CONSUMER1     = "N3S0";
  //string SOLAR_OVERFLOW_CONSUMER2     = "N4S0";
  string SOLAR_OVERFLOW_DAILY_MINUTES = "N5S0";
  ModuleParameter so = ModuleHelper.GetProperty(Domains.VIRTUAL, SOLAR_OVERFLOW_SENSOR, "Sensor.DigitalValue");
  ModuleParameter som = ModuleHelper.GetProperty(Domains.VIRTUAL, SOLAR_OVERFLOW_DAILY_MINUTES, "Sensor.AnalogValue");
  if (so.Value  == "1"){ // solar power has overflow
    int isom = Int32.Parse(som.Value);
    isom = isom + 1;
    DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_DAILY_MINUTES, "ControlLevel", isom.ToString());
  }
}

Program name: off-peak period begin
Cron Settings: 0 22 * * *
public void Setup(){
}

public void Run(){
  string SOLAR_OVERFLOW_WANTED_DAILY  = "N1S0";
  //string SOLAR_OVERFLOW_SENSOR        = "N2S0";
  string SOLAR_OVERFLOW_CONSUMER1     = "N3S0";
  string SOLAR_OVERFLOW_CONSUMER2     = "N4S0";
  string SOLAR_OVERFLOW_DAILY_MINUTES = "N5S0";
  
  ModuleParameter som = ModuleHelper.GetProperty(Domains.VIRTUAL, SOLAR_OVERFLOW_DAILY_MINUTES, "Sensor.AnalogValue");
  ModuleParameter sow = ModuleHelper.GetProperty(Domains.VIRTUAL, SOLAR_OVERFLOW_WANTED_DAILY, "Sensor.AnalogValue");
  int isom = Int32.Parse(som.Value);
  int isow = Int32.Parse(sow.Value);
  if (isow  >= isom){ // solar overflow limit NOT reached
    DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER1, "ControlOn", "");
    DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER2, "ControlOn", "");
  }
}

Program name: off-peak period end
Cron Settings: 0 6 * * *
public void Setup(){
}

public void Run(){
  //string SOLAR_OVERFLOW_WANTED_DAILY  = "N1S0";
  //string SOLAR_OVERFLOW_SENSOR        = "N2S0";
  string SOLAR_OVERFLOW_CONSUMER1     = "N3S0";
  string SOLAR_OVERFLOW_CONSUMER2     = "N4S0";
  string SOLAR_OVERFLOW_DAILY_MINUTES = "N5S0";
  DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER1, "ControlOff", "");
  DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_CONSUMER2, "ControlOff", ""); 
  DriverHelper.ProcessCommad(Domains.VIRTUAL, SOLAR_OVERFLOW_DAILY_MINUTES, "ControlLevel", "0");
}

How it goes:
- sumarize the minutes, solar overflow has switched the consumers on during the day
- at 22:00, decide if overflow was big enough to disable heating with off-peak electricity
- at 6:00 reset the overflow counter and disable the off-peak electricity consumers (if enabled last night or not)

thanks for all the help and documentation in this forum
chris

Please Log in or Create an account to join the conversation.

Time to create page: 0.314 seconds

Forum latest

  • No posts to display.