arkoode
(Arkoode)
June 20, 2023, 8:23pm
1
Hello, I have a Shelly SmartPlug an I need an automation that covers the follwing things:
I start with the following code:
alias: Shelly
trigger:
- platform: time
at: "09:00:00"
- platform: time
minutes: 60
seconds: 0
at: "00:00:00"
condition:
- condition: time
after: "09:00:00"
before: "18:00:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
action:
- service: switch.turn_on
entity_id: switch.shelly_switch
- delay: "00:15:00"
- service: switch.turn_off
entity_id: switch.shelly_switch
- service: notify.mobile_app
data_template:
message: >
Die Pool-Pumpe wurde {{ 'eingeschaltet' if is_state('switch.shelly_steckdose', 'on') else 'ausgeschaltet' }}.
Sie war {{ (now() - trigger.timestamp).total_seconds() // 60 }} Minuten aktiv.mode: single
max_exceeded: silent
But when I try to save it, I get the follwing error message: Message malformed: extra keys not allowed @ data[‘minutes’]
Thanks for help!
NathanCu
(Nathan Curtis)
June 20, 2023, 8:35pm
2
Look at lines 6 and 7 of your code. The Time platform of trigger doesn’t support minutes and seconds there?
arkoode
(Arkoode)
June 20, 2023, 8:46pm
3
Ah ok and whats the syntax for a 60min pause?
Maybe it wants 1 hour? Pretty sure I’ve ran into that before where it doesn’t like 60 seconds or minutes…
arkoode
(Arkoode)
June 20, 2023, 8:56pm
5
Lol, thats the magic:
- platform: time_pattern
hours: /1
Thanks to everybody for helping!
arkoode
(Arkoode)
June 21, 2023, 1:22pm
6
Ok one more question to this automation…
I didn’t get any notification and i dont know why :-S
AllHailJ
(J Gent)
June 21, 2023, 6:19pm
7
Have you considered something like this? I don’t think your if is_state is being executed correctly. I use a trigger id as well as all the times.
alias: Shelly Pool Pumpe
trigger:
- id "on"
platform: time
at:
- "09:00:00"
- "10:00:00"
- "11:00:00"
- "12:00:00"
- "13:00:00"
- "14:00:00"
- "15:00:00"
- "16:00:00"
- "17:00:00"
- "18:00:00"
- id "off"
platform: time
at:
- "09:15:00"
- "10:15:00"
- "11:15:00"
- "12:15:00"
- "13:15:00"
- "14:15:00"
- "15:15:00"
- "16:15:00"
- "17:15:00"
- "18:15:00"
condition:
action:
- service: switch.turn_{{ trigger_id }}
entity_id: switch.shelly_switch
- service: notify.mobile_app_<your device ID here> <------- this is from documentation and think you need ID
data:
message: >
{% if states('switch.shelly_steckdose') == 'on' %}
"Die Pool-Pumpe wurde eingeschaltet. Sie War {{ (now() - trigger.timestamp).total_seconds() / 60}} Minuten aktiv.mode: single"
{% else %}
"Die Pool-Pumpe wurde ausgeschaltet. Sie War {{ now() - trigger.timestamp).total_seconds() / 60 }} Minuten aktiv.mode: single"
{% endif %}
max_exceeded: silent
arkoode
(Arkoode)
June 21, 2023, 8:06pm
8
I tried your notification part and get the followin error message:
Message malformed: template value should be a string for dictionary value @ data['action'][3]['data']
AllHailJ
(J Gent)
June 21, 2023, 8:26pm
9
Do you have this in your YAML configuration
# Example configuration.yaml entry
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
I recommend you try it with just the words first.
so like this as a test
"Die Pool-Pumpe wurde eingeschaltet. Sie War Minuten aktiv.mode: single"
Did you add the device id as specified in the documentation. You should have also deleted my comment.
I was not specific so I thought I should clarify.
So from this
service: notify.mobile_app_<your device ID here> <------- this is from documentation and think you need ID
to this:
service: notify.mobile_app_pixel_7_pro
Hope this helps
arkoode
(Arkoode)
June 22, 2023, 1:01pm
10
hmm ok my if statement is the problem, without it, it works…
any idea how can i workaround it ? my configuration-file i already extend it and try again, same issue…
AllHailJ
(J Gent)
June 22, 2023, 3:51pm
11
I did some looking and there is no trigger.timestamp. However there is a trigger.now. It is defined as:
DateTime object that triggered the time trigger.
so I wrote a modified script in developer tools → templates like this
{% set trigger = now() %}
{% if states('switch.area_cans') == 'on' %}
"Die Pool-Pumpe wurde eingeschaltet. Sie War {{ (as_timestamp(now()) - as_timestamp(trigger)) | float(0) / 60 }} Minuten aktiv.mode: single"
{% else %}
"Die Pool-Pumpe wurde ausgeschaltet. Sie War {{ (as_timestamp(now()) - as_timestamp(trigger)) | float(0) / 60 }} Minuten aktiv.mode: single"
{% endif %}
This will basically display a small number of minutes and here is the result
as_timestamp converts the string datetime to a float of the number of seconds from jan 1 1970.
you need to change trigger in the yaml script to trigger.now like this:
{% if states('switch.shelly_steckdose') == 'on' %}
"Die Pool-Pumpe wurde eingeschaltet. Sie War {{ (as_timestamp(now()) - as_timestamp(trigger.now)) | float(0) / 60 }} Minuten aktiv.mode: single"
{% else %}
"Die Pool-Pumpe wurde ausgeschaltet. Sie War {{ (as_timestamp(now()) - as_timestamp(trigger.now)) | float(0) / 60 }} Minuten aktiv.mode: single"
{% endif %}
Here is a screenshot of the templates page
arkoode
(Arkoode)
June 28, 2023, 8:13pm
12
Hy, i really dont know what i am doing wrong … When i test the code in dev tools, it works but in my automation not :-S
AllHailJ
(J Gent)
June 28, 2023, 11:13pm
13
Can you please post the automation (formatted) as you have it installed.