seriksson
(Stefan E)
November 1, 2017, 2:38pm
1
I need some help with the creation of a car heater function (Living in Sweden) and winter is coming
I have an outside temp sensor and a switch to connect to the heater in my car.
If the temperature is < 10 i want the heater to start 30 minutes before the actual time to leave.
If the temperature is < 0 i want the heater to start 60 minutes before the actual time to leave.
If the temperature is < -10 i want the heater to start 90 minutes before the actual time to leave.
I also want the heater to run for 30 min after the actual time to leave (if I am late).
It would also be great if it could be started/stopped manually. Departure time could be set trough a google calendar or via an input_number slide.
I have searched trough the forum for this, but with no luckâŠ
This is way off my skills, so I trust in you guys
You can start with the alarm clock package: https://github.com/Danielhiversen/home-assistant_config/blob/master/packages/alarm_clock.yaml
Update the condition so that it will trigger if time less than 90 and temp < -10 or time less than 60 and temp < 0 or âŠ
Use the relative_time
() to calculate the relative time left before the sat temperature
1 Like
seriksson
(Stefan E)
November 1, 2017, 4:19pm
3
I am sorry, but it is little to complicated for me (as I donât have any programming background)
Cut and paste works
seriksson
(Stefan E)
November 2, 2017, 6:33am
4
@Danielhiversen , how to add the âextra timeâ (ex +90 min) time in condition? Condition for the temp sensor must also be added some where?
Will there be three different automations for the following?
If the temperature is < 10 i want the heater to start 30 minutes before the actual time to leave.
If the temperature is < 0 i want the heater to start 60 minutes before the actual time to leave.
If the temperature is < -10 i want the heater to start 90 minutes before the actual time to leave.
I am sorry for all the noob questionsâŠ
garvarma
(Manuel)
November 2, 2017, 11:48am
5
Hi,
When you refer to extra time, you mean that heater run for 30 min after actual time to leave?
Maybe this you can do it with presence detection of your wifi or geolocation.
First after beginning with automation, have you configured any automation in your HA?
seriksson
(Stefan E)
November 2, 2017, 12:35pm
6
@garvarma
Yes the extra time (30 min) is if I am late, and not leaving in time.
I have other automatons running in HA for light management.
@Danielhiversen
I have tried your code It works fine. But i need some help with the implementation of the time to run before actual time to leave and the temp sensor condition.
https://pastebin.com/SD5nKsdL
seriksson
(Stefan E)
November 6, 2017, 10:33am
7
Need some advice⊠Will this work?
https://pastebin.com/M0spLRAQ
You can change line 21 to False
If you go to HA_IP:8123/dev-template you can paste in the template to validate it.
For testing you can change the temperature values and time shift, to validate that the output changes to True when expected.
seriksson
(Stefan E)
November 7, 2017, 3:13pm
11
This is my attemptâŠ
Not so nice, but it works. All suggestions for better code is welcome
Thanks to @Danielhiversen for inspiration!
#########################################################################################################
# Car heater package #
# #
# Source https://github.com/Danielhiversen/home-assistant_config/blob/master/packages/alarm_clock.yaml #
# #
#########################################################################################################
# Automation section
automation:
- alias: "heater ak minus 10"
initial_state: True
trigger:
- platform: time
minutes: '/5'
seconds: 2
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.netatmo_utomhus_norra_husgaveln_temperature
below: -10
- condition: template
value_template: '{{ ((now().strftime("%s") | int + 7200) | timestamp_custom("%H:%M")) == states.sensor.departuretime_ak.state }}'
action:
- service: script.turn_on
entity_id: script.heater_ak_on
- service: notify.telegram
data_template:
message: 'MotorvÀrmaren (-10°) Àr pÄ i 2h frÄn {{now().strftime("%H:%M:%S")}} Temp ute: {{ states.sensor.netatmo_utomhus_norra_husgaveln_temperature.state}}°C'
- service: homeassistant.turn_off
entity_id: automation.heater_ak_minus_10, automation.heater_ak_plus_1, automation.heater_ak_plus_5
- alias: "heater ak plus 1"
initial_state: True
trigger:
- platform: time
minutes: '/5'
seconds: 2
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.netatmo_utomhus_norra_husgaveln_temperature
below: 1.0
- condition: template
value_template: '{{ ((now().strftime("%s") | int + 3600) | timestamp_custom("%H:%M")) == states.sensor.departuretime_ak.state }}'
action:
- service: script.turn_on
entity_id: script.heater_ak_on
- service: notify.telegram
data_template:
message: 'MotorvÀrmaren (+1°) Àr pÄ i 1h frÄn {{now().strftime("%H:%M:%S")}} Temp ute: {{ states.sensor.netatmo_utomhus_norra_husgaveln_temperature.state}}°C'
- service: homeassistant.turn_off
entity_id: automation.heater_ak_plus_1, automation.heater_ak_plus_5, automation.heater_ak_minus_10
- alias: "heater ak plus 5"
initial_state: True
trigger:
- platform: time
minutes: '/5'
seconds: 2
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.netatmo_utomhus_norra_husgaveln_temperature
below: 5.0
- condition: template
value_template: '{{ ((now().strftime("%s") | int + 1800) | timestamp_custom("%H:%M")) == states.sensor.departuretime_ak.state }}'
action:
- service: script.turn_on
entity_id: script.heater_ak_on
- service: notify.telegram
data_template:
message: 'MotorvÀrmaren (+5°) Àr pÄ i 30 min frÄn {{now().strftime("%H:%M:%S")}} Temp ute: {{ states.sensor.netatmo_utomhus_norra_husgaveln_temperature.state}}°C'
- service: homeassistant.turn_off
entity_id: automation.heater_ak_plus_5, automation.heater_ak_plus_1, automation.heater_ak_minus_10
- alias: "heater ak enabled"
trigger:
platform: state
entity_id: input_number.heater_ak_hour, input_number.heater_ak_minutes
action:
- service: homeassistant.turn_on
entity_id:
- automation.heater_ak_minus_10
- automation.heater_ak_plus_1
- automation.heater_ak_plus_5
- alias: "heater ak off"
initial_state: False
trigger:
- platform: time
minutes: '/5'
seconds: 2
condition:
- condition: template
value_template: '{{ now().hour == (states.input_number.heater_ak_hour.state | round(0)) and now().minute == (states.input_number.heater_ak_minutes.state | round(0) ) }}'
action:
- service: homeassistant.turn_off
entity_id: switch.carheater_ak_plug_switch, automation.heater_ak_off
- service: notify.telegram
data_template:
message: 'MotorvÀrmaren StÀngs nu av {{now().strftime("%H:%M:%S")}} Temp ute: {{ states.sensor.netatmo_utomhus_norra_husgaveln_temperature.state}}°C'
# Input section
input_number:
heater_ak_hour:
name: Timmar
icon: mdi:timer
initial: 07
min: 0
max: 23
step: 1
heater_ak_minutes:
name: Minuter
icon: mdi:timer
initial: 30
min: 0
max: 55
step: 5
# Sensor section
sensor:
- platform: template
sensors:
departuretime_ak:
friendly_name: 'Avresetid AK'
value_template: '{% if states.input_number.heater_ak_hour.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_number.heater_ak_hour.state|round(0)|string }}:{% if states.input_number.heater_ak_minutes.state|round(0)|string|length == 1 %}0{% endif %}{{ states.input_number.heater_ak_minutes.state|round(0)|string }}'
entity_id:
- input_number.heater_ak_minutes
- input_number.heater_ak_hour
# Group section
group:
heaterak:
name: Heater AK
icon: mdi:alarm
view: yes
entities:
- group.mvak
mvak:
name: "MotorvÀrmare AK"
entities:
- sensor.departuretime_ak
- sensor.heater_start_time_ak
- input_number.heater_ak_hour
- input_number.heater_ak_minutes
- sensor.netatmo_utomhus_norra_husgaveln_temperature
- switch.carheater_ak_plug_switch
# Script section
script:
heater_ak_on:
sequence:
- service: homeassistant.turn_on
#data:
entity_id: switch.carheater_ak_plug_switch
- service: automation.turn_on
entity_id: automation.heater_ak_off
3 Likes
choffe
(Christoffer)
December 9, 2017, 2:41pm
12
Hello fellow Swed. Copied your code and it works very good! Thanks for sharing!
1 Like
yabbah
(yabbah)
March 4, 2018, 1:20pm
13
I tried to create a nearly copy of your project. But I just have one tiny problem left, my code is not work.
I have tried in the dev-tool to check my template (the current time now is 14:17), if I run this:
â{{ ((now().strftime("%s") | int) | timestamp_custom("%H:%M")) }}â
â{{ (now().strftime("%s") | int -3600) | timestamp_custom("%H:%M") }}â
I got output 15:17 for the first line, and 14:17 on the second one. So it seems that my time is 1hour off. But âdateâ in cli gives the correct time (14:17).
Any ideas?
yabbah
(yabbah)
March 4, 2018, 3:53pm
14
I answer myself. My code work. But it seems that everything is use the correct time beside the sensors. They use utc-time. So my heater is start 1h earlier then I set. I canât find a setting to change this. I use âEurope/Stockholmâ as time_zone in configuration.yaml.
seriksson
(Stefan E)
March 4, 2018, 4:21pm
15
Strange, It shows correct time for me⊠(Also Europe/Stockholm.
Do you use hassio/docker?
yabbah
(yabbah)
March 4, 2018, 4:28pm
16
I use hass.io on a raspberry Pi.
Do you have:
platform: time_date
display_options:
âtimeâ
âtime_utcâ
in your configuration.yaml? Do they show the same time?
Mine show (current time 17:28)
Time: 17:28
Time (UTC): 16:28
seriksson
(Stefan E)
March 4, 2018, 5:40pm
17
Yes I use the time sensor. And utc is one hour behind.
I also run HA in a virtual environment. I know there was a guy in the Swedish Facebook group SHG that hade similar problems.
yabbah
(yabbah)
March 5, 2018, 9:06am
18
It was fixed by using utcnow() in the template-string.
I have been trying to get this to work for a couple of days now, but I canât get it going.
HASS gives me the following error Error loading /config/configuration.yaml: expected '<document start>', but found '<block mapping start>' in "/config/packages/motorv.yaml", line 99, column 1
Iâm using Atom as my editor and it outputs the another error for line 98 end of the stream or a document separator is expected
As far as I can tell the indentation is correct.
Please help!