Hi!
I have sonoff switches that are scheduled to switch on at fixed times (lovelace)
I would like to edit the time they stay on for through an input slider.
I tried making a helper and then converting it into a sensor which can be used with lovelace, but they allow only to read the states currently.
Any other way?
tom_l
July 4, 2022, 11:07am
2
Put the helper (input_number) your dashboard.
Yes!
I have the slider on the dashboard.
I cannot figure out how to switch off the switch after " input slider minutes"
I created the below automation that switches the pump on at preset times and switches it off after 3 minutes, can you check it and let me know what should I put at the delay value so it takes the slider value
alias: Watering
description: ''
trigger:
- platform: time
at: '07:30:00'
- platform: time
at: '12:30:00'
- platform: time
at: '17:30:00'
condition: []
action:
- type: turn_on
device_id:
entity_id: switch.sonoff_
domain: switch
- delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- type: turn_off
device_id:
entity_id:
domain: switch
mode: single
tom_l
July 4, 2022, 12:40pm
4
So why did you say this instead?
It helps if you ask your actual question. We are not mind readers.
This will turn your light off after the time (in minutes) specified in your input_number:
trigger:
- platform: state
entity_id: switch.sonoff_
to: 'on'
for:
minutes: "{{ states('input_number.your_slider_here')|int(1) }}"
action:
- service: switch.turn_off
target:
entity_id: switch.sonoff_
Keep this as your turn on automation:
alias: Watering
description: ''
trigger:
- platform: time
at: '07:30:00'
- platform: time
at: '12:30:00'
- platform: time
at: '17:30:00'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.sonoff_
Note: If you restart home assistant or reload automations (which happens when you save a new automation in the UI editor) it will interrupt/cancel the off timer automation. If that is likely to be an issue use these automations instead:
alias: Watering
description: ''
trigger:
- platform: time
at: '07:30:00'
- platform: time
at: '12:30:00'
- platform: time
at: '17:30:00'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.sonoff_
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.watering_off_time
data:
time: "{{ (now() + timedelta(minutes=states('input_number.your_slider_here')|int(1))).strftime("%H:%M:%S") }}"
trigger:
- platform: time
at: input_datetime.watering_off_time
condition: []
action:
- service: switch.turn_off
target:
entity_id: switch.sonoff_
You have to create the helper: input_datetime.watering_off_time
EDIT: this has been substantially corrected as below.
Hi!
I am so sorry if I was not clear.
I am able to get a slider on the dashboard by creating a helper for input number, I don’t know how to utilize it in the automation.
Thank you for your tip regarding the reloading automation part, I will be following your method!
So, I have to create one helper for input_number and another one for input_datetime, right?
The above code calls the switch to turn on and then the date time service?
Is the entity_id: input_datetime.XXX, correct? I did not understand the .XXX part
And where do I paste the below code?
trigger:
- platform: time
at: input_datetime.watering_off_time
condition: []
action:
- service: switch.turn_off
target:
entity_id: switch.sonoff_
tom_l
July 4, 2022, 1:33pm
7
Use input_datetime.watering_off_time instead of input_datetime.XXX. That was a mistake I have corrected above.
In another automation.
alias: Watering
description: ''
trigger:
- platform: time
at: '07:30:00'
- platform: time
at: '12:30:00'
- platform: time
at: '17:30:00'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.sonoff_
- service: input_datetime.watering_off_time
target:
entity_id: input_datetime.watering_off_time
data:
time: "{{ now() + timedelta(minutes=states('input_number.your_slider_here')|int(1) }}"
Hi!
Pasting this in the YAML editor gives the below error
Message malformed: template value should be a string for dictionary value @ data[‘action’][1][‘data’]
Google says its some punctuation error mostly, could you look at it once again?
tom_l
July 5, 2022, 6:49am
9
Did you change input_number.your_slider_here
to your slider entity id?
Did you create input_datetime.watering_off_time
?
It could also be this issue with the editor:
opened 01:22PM - 08 Apr 22 UTC
### The problem
In order to implement a somewhat more complex template conditio… n, I came across the problem that (at least testing) templates conditions do not work (anymore).
What I did:
Create a simple automation having a template condition:
```
- condition: template
value_template: "{{ 1 > 2 }}"
```
So, this is extremely simplifed. The expression should return False, but instead I get the following error when testing this expression in the condition frontend (under automatisations):
`Error handling message: template value should be a string for dictionary value @ data['value_template']. Got None (invalid_format)`
If I enter the same snippet of code in the templates section un der developer tools, it prints false.
Either there is a problem in the code just adding the template condition in the automatisation frontend or something is completely borked.
### What version of Home Assistant Core has the issue?
2022.4.1
### What was the last working version of Home Assistant Core?
_No response_
### What type of installation are you running?
Home Assistant Container
### Integration causing the issue
Automation
### Link to integration documentation on our website
_No response_
### Diagnostics information
_No response_
### Example YAML snippet
```yaml
- condition: template
value_template: "{{ 1 > 2 }}"
```
### Anything in the logs that might be useful for us?
```txt
2022-04-08 14:40:54 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140209354674720] Error handling message: template value should belue_template']. Got None (invalid_format)
```
### Additional information
_No response_
Oh shucks!
yes I did change input_number.your_slider_here
and I did create input_datetime.watering_off_time
.
I am editing in the automation tab itself, I’ll give it a try in the studio visual editor.
Will that make the automation work?
Anyway I can introduce input_datetime.watering_off_time
as a service and then add the automation through the UI editor?
tom_l
July 5, 2022, 6:59am
11
I don’t understand what you mean by this. It is an entity. Not a service.
You can use YAML mode in the UI editor.
Oh!
It was called as a service in the code, so I figured it had to be configured as one.
I am using the YAML mode in the UI Editor , that is what gave me the error
Tried pasting the code as you’ve mentioned in the automations.yaml file, the 2nd automation does not get called and the switch does not turn off
tom_l
July 5, 2022, 7:25am
13
Missed a bracket:
data:
time: "{{ now() + timedelta(minutes=states('input_number.your_slider_here')|int(1)) }}"
Still not working!
I am pasting the code for both the automations below
id: "1657002760640"
alias: 4x4 Watering
description: ""
trigger:
- platform: time
at: 07:30:00
- platform: time
at: "12:30:00"
- platform: time
at: "17:30:00"
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.sonoff_1000eca7dd
data: {}
- service: input_datetime.watering_off_time
target:
entity_id: input_datetime.watering_off_time
data:
time: "{{ now() + timedelta(minutes=states('input_number.4x4_watering_time')|int(1)) }}"
- id: "1657003150380"
alias: 4x4_Watering_Minutes_Slider
description: ""
trigger:
- platform: time
at: input_datetime.watering_off_time
condition: []
action:
- service: switch.turn_off
target:
entity_id: switch.sonoff_1000eca7dd
mode: single
Also, can this work?
After calling the switch.on service for the entity, I add an action for delay and entered the below code, where I substituted the minutes for the state of the slider, it gives me the float error
Error: expected float for dictionary value @ data[‘minutes’]
What am I missing to convert it into a float?
- delay:
hours: 0
minutes: {{ states('input_number.4x4_watering_time') | float(0)}}
seconds: 0
milliseconds: 0
- service: switch.turn_off
data: {}
target:
entity_id: switch.sonoff_1000eca7dd
tom_l
July 5, 2022, 8:44am
15
ratatouille:
Still not working!
Look at the automation traces to see why.
Also check what input_datetime.watering_off_time
set to after the on automation fires.
This is the error that I am getting now
Unable to find service input_datetime.watering_off_time
The value for the input_datetime.watering_off_time
does not change after switching on the automation, I have not set it to any value, it just shows 12:00 AM.
the 2nd step that calls for the switch to be off, does correctly calculate the time according to the slider though
params:
domain: input_datetime
service: watering_off_time
service_data:
time: '2022-07-05 14:36:19.492455+05:30'
target:
entity_id:
- input_datetime.watering_off_time
running_script: false
limit: 10
tom_l
July 5, 2022, 9:18am
17
Ok not sure what drugs I was on when I wrote that. It should be:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.watering_off_time
data:
time: "{{ now() + timedelta(minutes=states('input_number.your_slider_here')|int(1)) }}"
tom_l
July 5, 2022, 9:42am
19
You did not change it.
- service: input_datetime.set_datetime
Ahh! Sorry!
Now it says this
Invalid time specified: 2022-07-05 15:20:42.882263+05:30 for dictionary value @ data['time']
So I changed time to datetime and it works!!!
time: "{{ now() + timedelta(minutes=states('input_number.your_slider_here')|int(1)) }}"
to
datetime: "{{ now() + timedelta(minutes=states('input_number.your_slider_here')|int(1)) }}"
Thank you so much for your help!!
tom_l
July 5, 2022, 11:06am
21
Ok the other option would have been to format the time:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.watering_off_time
data:
time: "{{ (now() + timedelta(minutes=states('input_number.your_slider_here')|int(1))).strftime("%H:%M:%S") }}"
I’ll update the original automations in case anyone else see it.
1 Like