Hi,
How can I simplyfy and make these automations better?
The first one I could make a look to set the value on the input datetimes instead of calling each service in a separate block each time? Or just not use the input datetimes at all?
alias: VVB Strøm saver
description: ''
trigger:
- platform: time
at: '23:00'
condition: []
action:
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[0].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime1
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[1].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime2
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[2].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime3
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[3].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime4
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[4].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime5
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[5].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime6
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[6].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime7
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[7].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime8
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[8].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime9
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[9].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime10
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[10].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime11
- service: input_datetime.set_datetime
data:
timestamp: >-
{{
states('sensor.billige_timer_imorgen').split(',')[11].replace('[','').replace(']','')
}}
target:
entity_id: input_datetime.billigtime12
- service: notify.mobile_app_thomas_mobil
data:
message: Billige timer satt
mode: single
Which sets a series of input_datetime helpers from a unix timestamp array which can look like this:
[1644534000, 1644537600, 1644541200, 1644544800, 1644548400, 1644552000, 1644577200, 1644580800, 1644588000, 1644609600, 1644613200, 1644616800]
These datetimes are used as triggers in another automation which looks like this:
alias: VVB Av etter en time
description: ''
trigger:
- platform: time
at: input_datetime.billigtime1
- platform: time
at: input_datetime.billigtime2
- platform: time
at: input_datetime.billigtime3
- platform: time
at: input_datetime.billigtime4
- platform: time
at: input_datetime.billigtime5
- platform: time
at: input_datetime.billigtime6
- platform: time
at: input_datetime.billigtime7
- platform: time
at: input_datetime.billigtime8
- platform: time
at: input_datetime.billigtime9
- platform: time
at: input_datetime.billigtime10
- platform: time
at: input_datetime.billigtime11
- platform: time
at: input_datetime.billigtime12
condition: []
action:
- type: turn_on
device_id: c4d85a15f1e26ff043d4b628caf30968
entity_id: switch.varmtvannstank
domain: switch
- service: notify.mobile_app_thomas_mobil
data:
title: 'VVB PÅ Billig '
message: '{{now()}}'
- delay:
hours: 0
minutes: 59
seconds: 0
milliseconds: 0
- type: turn_off
device_id: c4d85a15f1e26ff043d4b628caf30968
entity_id: switch.varmtvannstank
domain: switch
- service: notify.mobile_app_thomas_mobil
data:
title: VVB AV 59min
message: '{{now()}}'
mode: single
Is there a better way to turn the device on again after 59 minutes, instead of using delay? If I restart HA during one of these hours the automation will not work as intended I guess? Another set of datetime helpers could be used where I just add 59 min to the Unix timestamp, but dealing with 24 helpers isnt ideal I guess