Turn boiler on or off by valve position

Begonnen von mflammia1, 07 November 2015, 09:43:57

Vorheriges Thema - Nächstes Thema

mflammia1

Hi,

In the process of trying to create the ability of turning my heating on when its needed based on radiator valve position. This is to be accomplished by turning the main heating thermostat on or off by replacement of a remote switch. To do this I have taken a snippet from the following link:

http://www.ply.me.uk/bits_and_pieces/fhem_snippets.html#ninetynine_myUtils.pm

Currently my remote switch is not switching on or off automatically.

So I've added the following to my 99_myUtilis.pm file:


######## Valve position heating control  ############
sub
valve_pos($)
{
#Log 3, "Valve position dependent heating control...";
my $threshold_val = $_[0];
my $valve = 0;
my @pos = ();
my $total = 0;
my @MAX=devspec2array("DEF=HeatingThermostat.*");
  foreach(@MAX) {
  $valve=ReadingsVal( $_, "valveposition", "101" );
  push(@pos,$valve);
  $total = $total + $valve;
  }
  if ( ( $total > $threshold_val ) && (ReadingsVal( "HM_302DB1", "state", "off" ) eq "off"))
  {
   fhem "set HM_302DB1 on";
   Log 3, "Heating ON: @pos, Total: $total, Threshold: $threshold_val"
  }
  elsif ( ( $total < $threshold_val ) && (ReadingsVal( "HM_302DB1", "state", "off" ) eq "on" ))
  {
   fhem "set HM_302DB1 off";
   Log 3, "Heating OFF: @pos, Total: $total, Threshold: $threshold_val"
  }
  else
  {
   Log 4, "Heating UNCHANGED: @pos, Total: $total, Threshold: $threshold_val"
  }
}


In my FHEM.cfg file I have added the following code:


#####################################################################
####    Heating control
#####################################################################
define HeatingThreshold dummy
attr HeatingThreshold event-on-change-reading .*
attr HeatingThreshold room Heat_Control
attr HeatingThreshold setList state:30,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,90,100
attr HeatingThreshold webCmd state

define at_HeatingCheck at +*00:15:00 {valve_pos( ReadingsVal( "HeatingThreshold", "state", "50" ) )}
attr at_HeatingCheck room Heat_Control

#####################################################################


In my code I have the following examples of MAX devices:


### Hall Wall Thermostat ###
define MAX_Hall_Thermostat MAX WallMountedThermostat 0f78ef
attr MAX_Hall_Thermostat IODev cm
attr MAX_Hall_Thermostat alias Hall Thermostat
attr MAX_Hall_Thermostat group Hall
attr MAX_Hall_Thermostat icon hm-tc-it-wm-w-eu
attr MAX_Hall_Thermostat room Hall,MAX,Thermostats
define FileLog_MAX_Hall_Thermostat FileLog ./log/MAX_0f78ef-%Y.log MAX_Hall_Thermostat
attr FileLog_MAX_Hall_Thermostat fm_type [{"title":"Temperature","id":"graph-temp","min":"auto:0","max":"auto:20","col":"a90000","h":2}]
attr FileLog_MAX_Hall_Thermostat group Hall
attr FileLog_MAX_Hall_Thermostat logtype text
attr FileLog_MAX_Hall_Thermostat room MAX

### Hall Wall Thermostat Chart ###
#define MAX_Hall_Thermostat_weblink SVG FileLog_MAX_Hall_Thermostat:max_temp:CURRENT
#attr MAX_Hall_Thermostat_weblink alias Hall Thermostat Chart
#attr MAX_Hall_Thermostat_weblink group Hall
#attr MAX_Hall_Thermostat_weblink label "Hall Thermostat Set-Temperature Min $data{min1}, Max $data{max1}, Last $data{currval1}"
#attr MAX_Hall_Thermostat_weblink room MAX

### Hall TVR ###
define MAX_Hall_TVR MAX HeatingThermostat 0ddfe1
attr MAX_Hall_TVR IODev cm
attr MAX_Hall_TVR alias Hall TVR
attr MAX_Hall_TVR fm_type desiredtemp,tempbutton,actuators
attr MAX_Hall_TVR group Hall
attr MAX_Hall_TVR icon hc_wht_regler
attr MAX_Hall_TVR room MAX
define FileLog_MAX_Hall_TVR FileLog ./log/MAX_0ddfe1-%Y.log MAX_Hall_TVR
attr FileLog_MAX_Hall_TVR fm_type [{"title":"Temperature","id":"graph-temp","min":"auto:0","max":"auto:20","col":"a90000","h":2}]
attr FileLog_MAX_Hall_TVR group Hall
attr FileLog_MAX_Hall_TVR logtype text
attr FileLog_MAX_Hall_TVR room MAX

### Hall TVR Chart ###
#define MAX_Hall_TVR_weblink SVG FileLog_MAX_Hall_TVR:max_temp:CURRENT
#attr MAX_Hall_TVR_weblink alias Hall TVR Chart
#attr MAX_Hall_TVR_weblink group Hall
#attr MAX_Hall_TVR_weblink label "Hall TVR Set-Temperature Min $data{min1}, Max $data{max1}, Last $data{currval1}"
#attr MAX_Hall_TVR_weblink room MAX




and the code for the switch I want to turn on and off is as follows:


define HM_302DB1 CUL_HM 302DB1
attr HM_302DB1 IODev CUL_1
attr HM_302DB1 autoReadReg 4_reqStatus
attr HM_302DB1 expert 2_full
attr HM_302DB1 firmware 2.5
attr HM_302DB1 model HM-LC-SW1-SM
attr HM_302DB1 peerIDs 00000000,
attr HM_302DB1 room CUL_HM
attr HM_302DB1 serialNr LEQ1211862
attr HM_302DB1 subType switch
define FileLog_HM_302DB1 FileLog ./log/HM_302DB1-%Y.log HM_302DB1
attr FileLog_HM_302DB1 logtype text
attr FileLog_HM_302DB1 room CUL_HM



and here's a couple of screenshots of what it looks like currently:

So my questions are if you know what might be wrong with my code and how I might be able to debug it, i.e check varibles, whats in the array, if I have put the correct devices in for MAX and remote switch etc.

Also be interested if this is the right way to go about it, maybe there is a simpler way or a different bit of code anyone would be willing to share.

Many thanks in advance

fruit

That's my code you have borrowed :) It's crude but it works here

Yours is so close to mine I may have missed something  but..
where you have defined your switch, do you have another device beneath that?

I have a two gang version which presents as three devices, the last two are the actual switches

define Switch_00 CUL_HM 1F6F42
define Pump_Switch CUL_HM 1F6F4201
define Boiler_Switch CUL_HM 1F6F4202

The single gang may be completely different of course.
Does set HM_302DB1 off work from the command line?
Feel free to follow up in German if you prefer

mflammia1

Hi There... Thanks for posting back....

That's handy. Thought about contacting you directly, often follow your blog :)

My theory was that I only needed one switch. I have a combination boiler that has a central thermostat. So all I typically do at the moment is use that thermostat to turn the boiler on or off and let the MAX system control each of the rooms separately.

Its not brilliant as I have one radiator in the kitchen that's typically on all on the time with no valve, so the system doesn't lock up.

I do have a separate programmer for the boiler which I will leave for the minute.

So the idea is that I just replace the main control thermostat for a single switch and just use your code to turn the boiler on and off based on valve position.

I am running a raspberry pi with two CUL Busware radios in, one for the MAX devices and one for the Homematic switch HM_302DB1 (long story). All works well and Homematic switch remotely switches on and off through FHEM.

Hope that answers your query?


fruit

Zitat von: mflammia1 am 07 November 2015, 17:17:13
My theory was that I only needed one switch. I have a combination boiler that has a central thermostat. So all I typically do at the moment is use that thermostat to turn the boiler on or off and let the MAX system control each of the rooms separately.
I'm sure you will be fine with the one switch but my question was - does it appear as just a single device or two. My 2 gang appears as 3 devices, only two switchable.
I guess you only have the one but do check - and check if the command line I gave works

As regards logging, you can add more logging lines similar to those already there, just edit the bit between quotes and the variables. The Log 3, at the beginnning of the line is log level - 3 here.
If you are editing the file in fhem, it's a good idea to copy to a desktop and use an editor with highlighting

The line Log 3, "Heating ON: @pos, Total: $total, Threshold: $threshold_val" shows the values in array @pos - $total and $threshold_val are variables
Feel free to follow up in German if you prefer

mflammia1

Hi,

It only appears as one device, it is just a single gang switch. The command you provided works fine for switching it on and off.

At the moment I am not seeing any messages in my log with the log entries that are already in the code, I believe I should have expected some by now?

When going into the 'at_HeatingCheck' section it indicates correctly when its going to do its next heating check. Just wondering if maybe something's not triggering the script?

Many thanks.

mflammia1

You know what...... it does actually work, amazing!!!

Just didn't test it properly.

So grateful for the code snippet, its very much appreciated :-)

Many thanks

fruit

Zitat von: mflammia1 am 07 November 2015, 19:54:16
You know what...... it does actually work, amazing!!!

Just didn't test it properly.

It's always the little things :)

Re. logging, there is a global attribute that sets default loglevel attr global verbose 3 that can be set between 1 and 5 - 5 is more
It can be overridden per device
Feel free to follow up in German if you prefer

ggaljoen

Thanks guys!

After reading this, it helped me adapt the code for my 2 heather pumps (downstairs & upstairs).
Made pump assignement by userattr for each radiator valve:

attr MAX_Livingroom_Heating1 userattr down

The trail and error code for now:

Pump_Guard()
{
my $threshold_val = 25;
#Log 3, "Pump_Guard Threshold: $threshold_val...";
#Log 3, "checking Down-stairs ...";
my $valve = 0;
my $actual_down = ReadingsVal( "MAX_Pomp0_Heating", "state", "off");
my $disered_down = "off °C";
my @MAX_Down=devspec2array("userattr=down");
  foreach(@MAX_Down) {
$valve=ReadingsVal( $_, "valveposition", "101" );
if ( $valve >= $threshold_val )
{
$disered_down = "on °C";
        Log 3, "Heater: $_, Valve: $valve";
}
  }
  #Log 3, "Actual: $actual_down, Disered: $disered_down";
  if ( $actual_down eq $disered_down )
  {
#Log 3, "nothing to do!";
  }
  elsif ( $actual_down eq "off °C" )
  {
Log 3, "Pomp0 is OFF switching ON";
    fhem "set MAX_Pomp0_Heating desiredTemperature on";
  } else
  {
Log 3, "Pomp0 is ON switching OFF";
    fhem "set MAX_Pomp0_Heating desiredTemperature off";
  }
#Log 3, "checking Up-stairs...";
my $actual_up = ReadingsVal( "MAX_Pomp1_Heating", "state", "off");
my $disered_up = "off °C";
my @MAX_Up=devspec2array("userattr=up");
  foreach(@MAX_Up) {
$valve=ReadingsVal( $_, "valveposition", "101" );
if ( $valve >= $threshold_val )
{
$disered_up = "on °C";
Log 3, "Heater: $_, Valve: $valve";
}
  }
  #Log 3, "Actual: $actual_up, Disered: $disered_up";
  if ( $actual_up eq $disered_up )
  {
#Log 3, "nothing to do!";
  }
  elsif ( $actual_up eq "off °C" )
  {
Log 3, "Pomp1 is OFF switching ON";
        fhem "set MAX_Pomp1_Heating desiredTemperature on";
  } else
  {
Log 3, "Pomp1 is ON switching OFF";
        fhem "set MAX_Pomp1_Heating desiredTemperature off";
  }
}


Maybe over-acting, demand trigger each 15 seconds:

define Pump_guard_cron at +*00:00:15 {Pump_Guard () }


There must be a better way, right?

Next try decently visualise the MAX on-off values in SVG.

Suggestions welcome.

fruit

Feel free to follow up in German if you prefer

chapelhill

Hi All.

I have managed to get many great ideas and bits from the ply me web site, many thanks to the author.
http://www.ply.me.uk/bits_and_pieces/index.html

I have developed mine a bit as I have more radiators so that I have a threshold on (default 180) default  and threshold off default (160) for the sum of the valve value for all the radiators (20 in total).
I have also added in a threshold on (25) and off (17) for the max value of any of the radiators in case for example I am working from home and only want heat in one or two rooms.

The two values for the threshold seems to create a reasonable on off so it will not turn the boiler off too quickly as that is inefficient.

I have also converted my Cube to run on the CUL firmware as I was fed up with having to reprogramme the MAX Cubes. Using the CUL firmware means you never have to do full re-programme, just each device if they have a problem. There was also a script to extract settings and save to file which I modified so that it is in the web interface format to just run command to set the time and temperatures for the week. Setting one device will likely use all available credits for 10 minutes or so.
http://forum.fhem.de/index.php/topic,38404.0.html

Since using the CUL firmware on MAX Cube rather than MAX Cube with eq3 software Fhem is notified much more regularly of changes so I have added a routine to not do the heating evaluation more regularly than around 3 minutes but to make sure the very last change is evaluated. Not entirely sure this was necessary but keeps my logs smaller.

I do have a programmable thermostat wired in to the system to as it was already there, but circuit is in parallel to heating switch set to 15 degrees in case Fhem/switch fails.

I am happy with system, the only thing that frustrates me is the credits, with approximately 20 radiators it would not be possible to regularly change the entire schedule, and even just setting to ecomode/comfortmode or auto is likely to max out the credits for a while meaning instruction to turn boiler on could be queued for over half an hour or more. I have been considering just implementing a dummy flag which would ignore call for heat unless either a minimum temp or average temp threshold is exceeded. The only disadvantage is probably radiator valve battery life. I do have another Cube, but FHEM is not quite ready for another cube within same instance.

I will try and tidy up my code and post if it can be of any help.






fruit

Zitat von: chapelhill am 18 Januar 2016, 16:32:12
I have managed to get many great ideas and bits from the ply me web site, many thanks to the author.url=http://www.ply.me.uk/bits_and_pieces/index.html]http://www.ply.me.uk/bits_and_pieces/index.html[/url]
Glad it has helped someone :)
Zitat
I have developed mine a bit as I have more radiators so that I have a threshold on (default 180) default  and threshold off default (160) for the sum of the valve value for all the radiators (20 in total).
I have also added in a threshold on (25) and off (17) for the max value of any of the radiators in case for example I am working from home and only want heat in one or two rooms.
Good idea. I tend to vary threshold depending on whether I'm home or not and how cold it is outside - not very automated!

ZitatI have also converted my Cube to run on the CUL firmware as I was fed up with having to reprogramme the MAX Cubes. Using the CUL firmware means you never have to do full re-programme, just each device if they have a problem.
Have you triid the new weekprofile module yet?

ZitatSince using the CUL firmware on MAX Cube rather than MAX Cube with eq3 software Fhem is notified much more regularly of changes so I have added a routine to not do the heating evaluation more regularly than around 3 minutes but to make sure the very last change is evaluated. Not entirely sure this was necessary but keeps my logs smaller.
attr event-on-update-reading no good here?

ZitatI do have another Cube, but FHEM is not quite ready for another cube within same instance.
I thought I read that the abiliy to use more than one CUL and MAX had been added recently but I may be mistaken.
Feel free to follow up in German if you prefer

chapelhill

ZitatSince using the CUL firmware on MAX Cube rather than MAX Cube with eq3 software Fhem is notified much more regularly of changes so I have added a routine to not do the heating evaluation more regularly than around 3 minutes but to make sure the very last change is evaluated. Not entirely sure this was necessary but keeps my logs smaller.
attr event-on-update-reading no good here?

I do use the event notify, but i there are 4 or five radiator valve updates within about a minute do not want to send lots of "on commands" on to the boiler switch when switch has not activated due to the MAX Credits queue, using the filter it should not send more than once every 3 minutes. On each evaluation the script knows boiler is still off but cannot tell there is "on command" in the queue.

ZitatI do have another Cube, but FHEM is not quite ready for another cube within same instance.
I thought I read that the abiliy to use more than one CUL and MAX had been added recently but I may be mistaken.

Thanks for that I will have another look at that to see what is required for second max cube on CUL Firmware. I would suspect that each device can only be pared to one Cube,  but would prefer if it could be switched between cube depending on available credit.

fruit

Ah yes, it hadn't occurred to me that lack of credits may upset things...

... and I see now that it was your own thread http://forum.fhem.de/index.php/topic,41103.0.html that I had remembered - and seems it may not be fully working yet
Feel free to follow up in German if you prefer

daveabbott007

Fruit and mflammia1
Many thanks for posting all of the above, you have helped a newbie successfully get off of a buggy MAX! Cube. i have been trying to understand fhem and work in a solution like this for weeks now (god bless google translate) and have not managed it until finding this thread this evening, half hour later it all works!
Max kudos to you Fruit!