Engine Heater

Posted on
Tue Oct 20, 2015 2:42 pm
andarv offline
Posts: 121
Joined: Jun 28, 2015
Location: Stockholm, Sweden

Engine Heater

I'm trying to figure out how to get indigo to preheat my car. I want to be able to set a departure time and then Indigo calculates for how long it needs to preheat depending on outside temp.
My knowledge of Python is none, but i couldn't see any other way?

Right now I'm stuck, not sure how subtract the preheat time from my variable the easiest way?
The travelTime variable is stored "21:21" - I could of course store it in some other format, but the variable is right now set from a controlpage so it has to somewhat user-friendly.

"startHeater = travelTime - diff" is just a representation of what i would like to do.

Code: Select all
from datetime import datetime

EngineHeater = indigo.devices[606496378]
outTemp = float(indigo.variables[1616368062].value)
travelTime = indigo.variables[138374955].value

if (outTemp < 7.0):    #Start 1 hour before departure time
      diff = 60
   if (outTemp < 0.0):    #Start 1.5 hours before departure time
         diff = 90
      if (outTemp < -10.0):    #Start 2 hours before departure time
         diff = 120   
         if (outTemp < -20.0):       #Start 3 hours before departure time
               diff = 180

[b]startHeater = travelTime - diff[/b]

indigo.server.log("Current time is: " + datetime.now().strftime("%H:%M"))
indigo.server.log("Outside Temperatur: " + str(outTemp))
indigo.server.log("Travel time is set at: " + travelTime)
indigo.server.log("Engine heater preheats for: " + str(diff))

if startHeater == datetime.now().strftime("%H:%M"):
   indigo.device.turnOn(EngineHeater)

Posted on
Tue Oct 20, 2015 3:13 pm
howartp offline
Posts: 3629
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Engine Heater

Ooh - what device is your engine heater??


Sent from my iPhone using Tapatalk

Posted on
Tue Oct 20, 2015 6:13 pm
FlyingDiver offline
Posts: 3208
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Engine Heater

howartp wrote:
Ooh - what device is your engine heater??


Sent from my iPhone using Tapatalk



He's probably using an appliance module of some kind. Most engine preheaters in the Northern US and Canada plug into a standard AC outlet.

To the OP - look at the Python docs for the datetime module (https://docs.python.org/2/library/datetime.html). You need to do the calculations using date objects, not formatted strings. Don't try to compare formatted strings, that's just going to break.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Oct 20, 2015 11:57 pm
howartp offline
Posts: 3629
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Engine Heater

FlyingDiver wrote:
howartp wrote:
Ooh - what device is your engine heater??


Sent from my iPhone using Tapatalk



He's probably using an appliance module of some kind. Most engine preheaters in the Northern US and Canada plug into a standard AC outlet.

Ah :-(

I hoped someone had found a separate device of some sort - UK doesn't have preheaters that plug in; you need keys in car and engine turned on - or an expensive BMW.


Sent from my iPhone using Tapatalk

Posted on
Wed Oct 21, 2015 3:06 am
durosity offline
User avatar
Posts: 3776
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Engine Heater

howartp wrote:
or an expensive BMW.


Or an electric car.. prices start at £13,445 ;)

Computer says no.

Posted on
Wed Oct 21, 2015 3:37 am
howartp offline
Posts: 3629
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Engine Heater

durosity wrote:
howartp wrote:
or an expensive BMW.


Or an electric car.. prices start at £13,445 ;)

Already on my shopping list... ;-)


Sent from my iPhone using Tapatalk

Posted on
Wed Oct 21, 2015 3:57 am
DaveL17 offline
User avatar
Posts: 4886
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Engine Heater

You're on the right track. You need to think of two states of your variables for time. Indigo stores the information as a string whereas you need to do your math on datetime objects. Here's what I did to get you going:

- change the import statement to 'import datetime' (this changes how we refer to datetime objects, but they work the same way.)
- your if statements weren't properly indented.
- you put BB Code markup around your 'startHeater' line (I took it back out).
- when the temperature is 20 below, your if statements are all true. For all intents and purposes, this is okay, but I changed it to make it so only one condition is true at a time.
- convert travelTime to a datetime object using strptime.
- created a timedelta for the diff time.
- created a line so that you can see what time the heater kicks off.
- Your heater would only kick off if startHeater time was equal to now. You want to have the evaluation be a bit more forgiving (else it will only run when the two are equal.)


I think that's it. This is untested so please check my work. Also, you might consider letting Indigo manage the timer for how long the heater is on. Just a thought. If you have any questions about my mods to your script, don't hesitate to ask!
Dave

Code: Select all
import datetime

EngineHeater = indigo.devices[606496378]
outTemp = float(indigo.variables[1616368062].value)
travelTime = indigo.variables[138374955].value

if (0.0 < outTemp <= 7.0):    #Start 1 hour before departure time
    diff = 60
elif (-10.0 < outTemp <= 0.0):    #Start 1.5 hours before departure time
    diff = 90
elif (-20 < outTemp <= -10.0):    #Start 2 hours before departure time
    diff = 120   
elif (outTemp <= -20.0):       #Start 3 hours before departure time
    diff = 180
else:
    pass

travelTime_obj = datetime.datetime.strptime(travelTime, "%H:%M")
startHeater = travelTime_obj - datetime.timedelta(minutes=diff)

indigo.server.log("Current time is: " + datetime.datetime.now().strftime("%H:%M"))
indigo.server.log("Outside Temperature: " + str(outTemp))
indigo.server.log("Travel time is set at: " + travelTime)
indigo.server.log("Engine heater preheats for: " + str(diff))
indigo.server.log("Engine starts at: " + datetime.datetime.strftime(startHeater, "%H:%M"))

if startHeater < datetime.datetime.now():
   indigo.device.turnOn(EngineHeater)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Oct 21, 2015 1:21 pm
andarv offline
Posts: 121
Joined: Jun 28, 2015
Location: Stockholm, Sweden

Re: Engine Heater

Thanks! It worked "out of the box".

I tried with the timedelta after reading the documentation for python, but never really got the hang of it. That's because I don't really understand how the different objects work. Right now I'm only at a strictly int, float or str level. Time/date and calculations is a lot harder than it looks, but this at least gives me a starting point.

Wouldn't have thought of the fact that the heater only would have kicked in when the time matched exactly.
And as you say, a timer to control is a future upgrade, it would be easier to prolong the heating period for the times you're running late (which seams to be always).

It's as pointed out, just a relay turning a socket on/off. My cars are prepared with an electric block heater for the engine and a heating fan for the compartment. One is equipped with a diesel heater as well but it's a waste to burn fuel at home or at work.

Posted on
Wed Oct 21, 2015 1:24 pm
FlyingDiver offline
Posts: 3208
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Engine Heater

andarv wrote:
It's as pointed out, just a relay turning a socket on/off. My cars are prepared with an electric block heater for the engine and a heating fan for the compartment. One is equipped with a diesel heater as well but it's a waste to burn fuel at home or at work.


How far north are you? I'm from Upstate NY, but heaters are not common there. I did work for a company based in Edmonton AB for a while, and they were a pretty common there.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Oct 21, 2015 1:36 pm
andarv offline
Posts: 121
Joined: Jun 28, 2015
Location: Stockholm, Sweden

Re: Engine Heater

FlyingDiver wrote:
How far north are you? I'm from Upstate NY, but heaters are not common there. I did work for a company based in Edmonton AB for a while, and they were a pretty common there.


Stockholm, Sweden. This far south I would guess that 10-20% of the cars have some kind of heater, further north it's a lot more common. Here we have around 10 days below -15 C and 40-50 below -5C.

Posted on
Wed Oct 21, 2015 1:43 pm
DaveL17 offline
User avatar
Posts: 4886
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Engine Heater

Glad to hear that this worked for you. Once you get the hang of time in Python, it's not too bad.

In the early 90's I did some work in central North Dakota where the wind chill bottomed out at -80F (-20 ambient.) I knew I was in trouble when I was handed my rental car keys and an extension cord... :D


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Oct 21, 2015 2:04 pm
FlyingDiver offline
Posts: 3208
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Engine Heater

I spent a week in Edmonton one winter. I knew what winters there were like. The sales reps that came from the southern part of the US thought a raincoat with a liner was a winter coat. Oops.

It was close to -35 that week. Doesn't matter what scale you're on for that temp...

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Oct 21, 2015 2:24 pm
andarv offline
Posts: 121
Joined: Jun 28, 2015
Location: Stockholm, Sweden

Re: Engine Heater

Home automation - It's a luxury when you don't have to use an ice scraper every morning when your in a rush. Next step would be to use the prognoses from WU and my work calendar :)

Posted on
Wed Oct 21, 2015 3:32 pm
DaveL17 offline
User avatar
Posts: 4886
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Engine Heater

I like WU.


Sent from my iPhone using Tapatalk

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Oct 21, 2015 8:46 pm
RogueProeliator offline
User avatar
Posts: 2221
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Engine Heater

The sales reps that came from the southern part of the US thought a raincoat with a liner was a winter coat. Oops.

Hey, we know what a winter coat is down here! It's what we put on when it gets down to 40 degrees (Fahrenheit)...

And one slight code correction...
Code: Select all
elif (outTemp <= -20.0):       #Start 3 hours before departure time
    diff = 180
should actually be
Code: Select all
elif (outTemp <= -20.0):       # Stupidly cold condition
    travelTime = u"AIN'T NO WAY I'M GOING OUT IN THIS @#^@$^&@"
    indigo.server.log(u'Canceling trip.', isError = 'You bet your life'))

Who is online

Users browsing this forum: No registered users and 1 guest