Ah yes, exactly! Is it possible to put in action part of automation, or should I just create another automation that handles turning off the heater if current time is alarm clock time?
It is possible to have it in the same automation, but I would suggest creating a second automation.
Will do, it will keep this simpler I think Thank you a lot!
One thing though: I have read somewhere that itâs not âbest practiceâ to have automations to trigger every minute (or check conditions more like), right? But to me most important thing is that I get this beast finally working, itâs not as this automation was clogging my Raspberry, even if (and when) I will create another of these so that both of our car heaters are covered
It would be âbetterâ to have an automation that only triggers 3 hours, 2 hours and 1 hour before the clock, but I canât think of an easy way to have this in one automation, you could add a trigger for each of these and keep the conditions, but I think this would make it more complex than it needs to be. And anyway this should not affect your performance at all.
Thatâs what I thought as well. I rather have it easy than more complex than itâs necessary Earlier I just had three automations, now I get by with two (one for turning on the heater, and another one to turn it off). Thatâs fine by me, especially since the code is âcleanerâ than what I had before!
Ah âGlasshopperâ (1970âs TV reference you may not get) you give me pride in your accomplishments but also humour at your naivety. This too can be done with a service template.
You prove there is life in the old Mutt yet
Let me get to a workstation âŚ
Though, what Iâd suggested to Gilean was that as we are triggering every minute to test, we even out the granularity of the response, save fuel/energy and do it dynamically.
Ie
We donât consider any case before 180 mins before set time, we turn off at set time and at any time between we calculate if the heater needs switching.
160 - (Temp * -16) = minutes after the 3hrs before (sounds weird)
So letâs say itâs -10 degrees
160 - (-10 * - 16) = 0 so switch now (ie set time - 180 + 0) 180 mins of heat
-5 degrees : -
160 - (-5 * - 16) = 80 so switch after 80 mins (ie set time - 180 + 80) 100 mins of heat
0 degrees
160 - (0 * - 16) = 160 so switch after 160 mins (ie set time - 180 +160) 20 mins of heat
1 degree
160 - (1 * - 16) = 176 so switch after 176 mins (ie set time - 180 +176) 4 mins of heat
2 degrees
(160 - (2 * - 16) = 192 so is outside time to switch - ignored, 0 mins of heat
This is dynamic, done minute by minute so will adapt to changing weather and assuming linear heat gain should always achieve the same final temp at âset timeâ
Edit: note the âfunnyâ formula is because even at 0 degrees he wanted âsome heatingâ (must be a namby pamby southernerâ )
This will also eliminate two of the three evaluations but add a little complication as we are also switching off
Definitely too young to get this reference
I know that it is possible to do this. To be honest, I just didnât want to spend more time and make it more complex, because (I think) OPs needs were covered with my sample code. If I were at home right now, Iâd probably try to figure it out, however at work itâs a bit hard (and I should be working anyway ) to do this.
I really like your suggestion of making this whole thing more dynamic and I canât wait to see your solution
I like the word âdynamicâ
Well, considering that I live in Finland, I think itâs safe to say I am not âsouthernerâ except from reindeerâs point of view Anyway, the official reason I want heater still work up until +2C is that âcar peopleâ say itâs good for your car, actually you should heat your car always if itâs under +5C but⌠The unofficial reason is that I also have Defa interior heater that takes care of ice from windshield and moisture if itâs near or just above zero.
Understood.
If you read burnings note itâs also true that you can âovercomplicateâ things.
So just stop if things are going too far.
You have to keep and maintain this stuff after all.
But I think given the course of the above thread you know when to call it a day.
This is now an interlectual excersise for burning as heâs relatively new to this (hard to believe isnât it ? And Iâve already told him that Iâll be seeking his advice soon )
In the UK there is a bridge over the Tyne (River) it was put up for the millennium. It is said that on its southern end it has 8 coats of protective paint. On the northern side, it has ânoneâ âcos its not a puftaâ (âpuftaâ is a derogatory term, in this case used to mean ânamby pambyâ but it âcanâ be used in a homophobic context also, so thinking about this I should have found another term but this use is authentic âgeordieâ).
Geordies (people from this region) are renown for being tough and often go out in sub-zero temperatures âwithout a coatâ
Edit: I also believe, that if we give you a formula and an implementation, you will understand it well enough to tweak the formula to your needs given some time working with it and judging the resultant temperature.
all this is doing is adding strings together safely.
an alternative would have been to use + signs.
(now().date() | string
returns the date in this format 2020-30-1
now().date() | string ~ 'T'
just adds T at the end for 2020-30-1T
now().date() | string ~ 'T' ~ states('sensor.alarm_clock2_time')
we just keep adding to it, ending up with 2020-30-1T08:00
now().date() | string ~ 'T' ~ states('sensor.alarm_clock2_time') ~':00'
adding more, ending with a format that as_timestamp can parse naturally: 2020-30-1T08:00:00
.
Youâd get the same thing with
now().date() | string + 'T' + states('sensor.alarm_clock2_time') + ':00'
Ahha! Now thatâs informative post, thank you! I had no idea that as_timestamp needed such format for it to work! Some other solutions have been converting time to integer, then to Unix timestamps, then do the math and then converting back to ânormalâ time format. I think my old solution used that method but it was very complexâŚ
Yah this is probably one of the easier ways to get a usable datetime objects. But you gotta know the format.
The most astonishing part was that he apparently wrote up that code without testing, and it was the only code that worked straight out of box (except for minor typo with sensor name but that one I could fix myself ). I mean, itâs not that I donât appreciate people helping me because I really do, but for someone who doesnât understand code much, it can be quite overwhelming to see various different methods of achieving things, and when none of them work because of some minor in syntax and I cannot see it (and template editor is just saying âunknown errorâ or something like that)
That is true, except if the code has lots of conversions and () | {* characters, then itâs different story⌠And unfortunately for this automation, there just has to be those, more or less For example, in that Burningstoneâs conditions, there is [0:5] that I have no idea why and what that does⌠But still, that code is simple enough for me to adjust it as needed
Thatâs one of mine,
It allows you to compare times as strings rather than as timestamps
EDIT: this ONLY works with times in the sameday or if you test for a wrap around (over midnight) when comparing two values
It takes the first 5 characters of the string, maybe this isnât needed, however I didnât know if your alarm clock sensor has this â00:00:00â or this â00:00â format.
To be precise it takes the beginning of the string from position 0 _ upto but not including position 5
(in effect the first 5)
BUT
you can also do it in reverse with the end of the string, this is useful if your time also has date as this will work with both
[-8:-3]
so
{{ â12:34:45â [-8:-3] }} returns 12:34
Edit This last was robbed kindly donated from pnbruckner
Jinja (the language used for templates in home assistant) is a template engine for Python, so most of things will work the same/similar as in Python.
The [0:5] is called string slicing in python, you can read up on it here in case you are interested.
Itâs things like these that make me wish there was somewhere a website with lots of (Jinja/Python/YAML) code and user could click anywhere and you could see a small tooltip explaining what that thing does. For example, your explanation with this example would have been perfect for that
Yeah, but it would need someone like @petro to do it, and his contention is that itâs just jinja wrapped python (true) but it would be nice to have a site with standard examples for various template usages.
Instead âthese are just things we pluck from the hedgerows of experienceâ.
And I also think that petro has enough on his plate
And youâd be amazed at how differently some people attack the same problems with different approaches, and we learn new wrinkles all the time
you donât need to include the zero [:5]
is the same
Jinja is based on python, donât know if itâs a wrapped version of it.