Car heater timer

56 views
Skip to first unread message

Erik Trapp

unread,
Oct 15, 2016, 9:33:15 AM10/15/16
to OpenRemote
Hi!

I'm trying to figure out how to make a departure timer to control a wall socket for my car heater.
I have a working system with 4 sliders to set start and stop hour and minute but the goal is to only set the desired departure time (hour and minute) and then have openremote to calculate when to switch on the socket based on outside temperature.

What I am trying to achieve is if the outside temperature is above 0°C then the heater should start one hour before the set departure time.
Between 0 and -5°C, 1,5 hours before departure time.
Between -5 and -10°C, 2 hours before dt.
Below -10°C, 3 hours before the set departure time.

This is an example how I use the temp sensor i other rules: 
  CustomState( source == "oregon1temp", eval(Float.parseFloat((String)value) < -5.0 ))


Have any of you guys any suggestions on how I can solve this?


This is how the timer is configured at the moment:

rule "Start car heater"
when
 
CustomState( source == "GVMonSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "1" ) ||
 
CustomState( source == "GVTueSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "2" ) ||
 
CustomState( source == "GVWedSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "3" ) ||
 
CustomState( source == "GVThuSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "4" ) ||
 
CustomState( source == "GVFriSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "5" ) ||
 
CustomState( source == "GVSatSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "6" ) ||
 
CustomState( source == "GVSunSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "7" )
 
CustomState( source == "GVActivateTimer1Status", value == "on" )
 
Event( source == "TimeSweHour", $htime1:value )
 
Event( source == "GVStartTimeHour1", value == $htime1 )
 
Event( source == "TimeSweMinute", $mtime1:value )
 
Event( source == "GVStartTimeMinute1", value == $mtime1 )
then
  execute
.command( "Garage Socket(ON)" );
end


rule
"Stop car heater"
when
 
CustomState( source == "GVMonSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "1" ) ||
 
CustomState( source == "GVTueSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "2" ) ||
 
CustomState( source == "GVWedSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "3" ) ||
 
CustomState( source == "GVThuSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "4" ) ||
 
CustomState( source == "GVFriSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "5" ) ||
 
CustomState( source == "GVSatSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "6" ) ||
 
CustomState( source == "GVSunSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "7" )
 
CustomState( source == "GVActivateTimer1Status", value == "on" )
 
Event( source == "TimeSweHour", $htime2:value )
 
Event( source == "GVStopTimeHour1", value == $htime2 )
 
Event( source == "TimeSweMinute", $mtime2:value )
 
Event( source == "GVStopTimeMinute1", value == $mtime2 )
then
  execute
.command( "Garage Socket(OFF)" );
end


Cheers,

Erik

Michal Rutka

unread,
Oct 16, 2016, 7:28:24 AM10/16/16
to OpenRemote
Hi Erik,

a similar problem was presented in my retrofit airco project. There was a cooling problem but it can easily be adopted to the adoptive heating.

Kind regards,
Michal 
Message has been deleted

Erik Trapp

unread,
Oct 23, 2016, 9:17:26 AM10/23/16
to OpenRemote
Hi Michal,

I try to use some parts from your air-conditioning code just to set the time but I have stuck and only get this error message:

ERROR 2016-10-23 15:00:52,511 : Rule definition 'CarHeater.drl' could not be deployed. See errors below.
ERROR 2016-10-23 15:00:52,512 : Rule Compilation error The method _ShiftTime(String, int) is undefined for the type Rule_CarHeaterTimeInc1227608620
ERROR 2016-10-23 15:00:52,513 : Rule Compilation error The method _ShiftTime(String, int) is undefined for the type Rule_CarHeaterTimeDec816805169


This is the rule so far:

package org.openremote.controller.protocol;
import java.util.concurrent.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.*;
import org.openremote.controller.model.event.*;

global org.openremote.controller.statuscache.CommandFacade execute;



rule "inc/dec clear"
  salience -10
  timer(int:300ms)
when
  Event($s:source matches "^.*\\.(de|in)c$", value!="OFF")
then
  execute.command($s,"OFF");
end


rule "CarHeaterTimeInc"
  timer(int:300ms) // debounce & protect double click
when
  Event(source == "GVCHTime", $v: value)
  Event($s:source == "CHTime.inc" , value == "ON")
then
  execute.command($s,"OFF");
  execute.command("GVCHTime", _ShiftTime($v.toString(), 5));
end


rule "CarHeaterTimeDec"
  timer(int:300ms)
when
  Event(source == "GVCHTime", $v: value)
  Event($s:source == "CHTime.dec" , value == "ON")
then
  execute.command($s,"OFF");
  execute.command("GVCHTime", _ShiftTime($v.toString(), -5));
end

/Erik

Michal Rutka

unread,
Oct 24, 2016, 3:33:13 AM10/24/16
to openremot...@googlegroups.com
Hi,

probably some functions are missed. Simply copy it to the rule's file:

function String _ShiftTime(Object o, int min){

  String mt = o.toString();

  if(mt.equals("")){mt="-";}

  SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

  Date date = null;

  if(mt.substring(0,1).equals("-")){

    date = new Date();

    date.setTime(date.getTime()+60*60000);

  }else{

    date = sdf.parse(mt);

    date.setTime(date.getTime()+min*60000);

  }

  return(sdf.format(date));

}

Reply all
Reply to author
Forward
0 new messages