Meaning, the code I posted, doesn’t work? Or do you just want an explanation?
In the snippet I posted, the duration will be type casted to INT
or Integer
or at least should get type casted…
sorry, my answer was a little short. Yes, I took over your code. The template logic is now correct. Unfortunately, the condition still does not change after 2 minutes. I think it’s because of the ‘120’. But I have no idea how to solve this (I’m not a programmer and not familiar with int.).
If you have the solution as code, that would be perfect.
I found the problem. The countdown is not an attribute. Just the start (and remaining) time. But both are not change, if you start the countdown. So isn’t possible to make a condition: https://github.com/home-assistant/core/issues/30062
Would you please let me know what am I doing wrong on this automation? The problem is on the trigger/condition. Thanks in advance.
- id: 'Start Cooking Timer When Temp Reached'
alias: 'Start Cooking Timer When Temp Reached'
trigger:
platform: numeric_state
entity_id: sensor.temperature
condition:
condition: template
value_template: "{{ (states('sensor.temperature') | int) >= (states('input_number.cooking_temperature') | int) }}"
action:
- service: timer.start
data_template:
entity_id: timer.cooking_timer
duration: "00:{{ states('input_number.cooking_time') | int }}:00"
Thanks for pointing that out. Maybe when I copied the code that line got moved but the original is correct. Nevertheless, I checked my code just to make sure, I went through the indentation again and that didn’t solve the problem.
When I check my configuration, it says that’s valid but when I reload automations I get a persistent notification saying that: The following integrations and platforms could not be set up: * automation Please check your config.
If I comment out the condition section then I can reload the automation without a problem. Thanks for your willingness to help.
that points to your configuration not being correct. Can you post your full automation section here?
My entire automation file is 2400 lines long. This is the automation that is giving me trouble:
- id: 'Start Cooking Timer When Temp Reached'
alias: 'Start Cooking Timer When Temp Reached'
trigger:
platform: numeric_state
entity_id: sensor.temperature
condition:
condition: template
value_template: "{{ (states('sensor.temperature') | int) >= (states('input_number.cooking_temperature') | int) }}"
action:
- service: timer.start
data_template:
entity_id: timer.cooking_timer
duration: "00:{{ states('input_number.cooking_time') | int }}:00"
When I check the configuration it says that’s valid. But when I reaload the automation it gives me the error. If I comment out the condition statement, it loads fine.
I don’t know what to tell you. You aren’t providing the information to help solve the problem. The automation syntactically is correct. Without seeing the full context, I cannot help.
I really appreciate your interest on helping. I found the problem. Under the trigger section I didn’t have a the required parameter above (or below) As soon as I added the above: 50 everything works fine. Thanks again for your help.
- id: 'Start Cooking Timer When Temp Reached'
alias: 'Start Cooking Timer When Temp Reached'
trigger:
platform: numeric_state
entity_id: sensor.temperature
above: 50
condition:
condition: template
value_template: "{{ (states('sensor.temperature') | int) >= (states('input_number.cooking_temperature') | int) }}"
action:
service: timer.start
data_template:
entity_id: timer.cooking_timer
duration: "00:{{ states('input_number.cooking_time') | int }}:00"
Would it be possible to share the code for this?
Thanks!
Found a pretty good solution using custom:button-card so sharing here. It shows the icon of the light with the timer and colors it appropriately. It also reacts to taps to turn it on and off manually. Then the time remaining before the light goes off is displayed below the icon.
type: conditional
conditions:
- entity: timer.timer_garage
state_not: nothing
card:
type: 'custom:button-card'
entity: timer.timer_garage
icon: 'mdi:lightbulb'
name: Garage
show_state: true
show_label: true
show_icon: true
size: '7%'
tap_action:
action: call-service
service: light.toggle
service_data:
entity_id: light.jasco_products_zw7101_smart_led_light_bulb_ze26i_level
styles:
icon:
- color: |
[[[
if (states["light.jasco_products_zw7101_smart_led_light_bulb_ze26i_level"].state == 'off') return 'deepskyblue';
else return 'yellow';
]]]
Ok… I’m tired of banging my head against the HA wall… Its time to ask for help… I know its me… its always me! LOL
Timer declaration…in config yamal
The automation in automations.yamal
The script in scripts.yamal
and the UI
I’m getting an error in the logs concerning the timer…
and line 46…
Thanks in advance!
indent message
2 spaces. Also please post text next time, not images. Thanks.
Lastly, you can decipher the error messages without consulting the help desk. It’s telling you exactly what’s wrong.
extra keys not allowed @ data['action'][0]['message']
↑ ↑ └───────This is what it does not expect, it is the 'extra key'
| └─── This means first item
this is only in automations...
the first action in an automation’s action has an unexpected key “message”
Petro…
As usual thanks for your reply!
I thought Id circumvent the back and forth by just posting the actual code…
Thanks again… I’ll implement and check back!
-Aaron
Can anyone help explain why my timer correctly runs out to the full duration, however the countdown display on the dashboard always starts at 30 seconds less whatever I put in?
E.g for this 2 minute, (OK one second after hitting it!) I get this:
Or if it’s a 1 min timer, it displays 30 etc etc.
Then at the end of the last 30 seconds, just displays ‘Active’, then finally at the ‘real’ zero, switches to idle.
In other words, although it works correctly, the display is always 30 seconds fast.
This is my script to start the timeer:
alias: 'Timer Start Seth '
sequence:
- service: timer.start
data_template:
entity_id: timer.seth_timer
duration: 00:{{ states('input_number.timer_minutes') | int }}:00
mode: single
icon: mdi:alpha-s-circle-outline
The timer and input number are just very basic helpers.
Thanks!!
how does this trigger the timer? When I click the button, the light toggles, but the timer still remains ‘idle’.
Also, before the timer is triggered, the button shows idle. Is there anyway to hide this ‘idle’ while the timer has not yet been started, and only display the time counting down on the button only while the timer is active?
Here’s an update to my button timer view. I’ve now incorporated a bar-card that displays the remaining time as a progress bar underneath the button status.
type: horizontal-stack
cards:
- type: vertical-stack
cards:
- type: custom:button-card
entity: switch.back_porch_switches
icon: mdi:coach-lamp
name: B. Porch
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
- type: conditional
conditions:
- entity: timer.back_porch
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.back_porch_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
entity: switch.front_porch
icon: mdi:coach-lamp
name: F. Porch
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
- type: conditional
conditions:
- entity: timer.front_porch
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.front_porch_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
entity: light.driveways
icon: mdi:outdoor-lamp
name: Driveway
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
- type: conditional
conditions:
- entity: timer.driveway
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.driveway_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
entity: switch.garage
icon: mdi:lightbulb
name: Garage
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
tap_action:
action: toggle
hold_action:
action: more-info
double_tap_action:
action: more-info
- type: conditional
conditions:
- entity: timer.garage
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.garage_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
entity: switch.utility
icon: mdi:lightbulb
name: Utility
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
- type: conditional
conditions:
- entity: timer.diffuser
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.diffuser_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
entity: light.kitchen_bar
icon: mdi:glass-mug
name: Kit. Bar
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
- type: conditional
conditions:
- entity: timer.kitchen_bar
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.kitchen_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
icon: mdi:spotlight-beam
entity: light.kitchen_main
name: Kit. Main
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
animation:
state: 'on'
tap_action:
action: toggle
hold_action:
action: call-service
repeat: 1000
service: script.kitchen_main_cycle
double_tap_action:
action: more-info
- type: conditional
conditions:
- entity: timer.kitchen_main
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
tap_action:
action: call-service
service: script.timer_kitchen_main_toggle
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.kitchen_main_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
icon: mdi:lightbulb-group
entity: light.kitchen_cabinets
name: Kit. Cabinets
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
animation:
state: 'on'
- type: conditional
conditions:
- entity: timer.kitchen_main
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.kitchen_main_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
icon: mdi:ceiling-light
entity: light.kitchen_dining
name: Kit. Dining
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
animation:
state: 'on'
- type: conditional
conditions:
- entity: timer.kitchen_main
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.kitchen_main_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
icon: mdi:globe-light
entity: switch.hallway
name: Hallway
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
animation:
state: 'on'
- type: conditional
conditions:
- entity: timer.hallway
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.hallway_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
icon: mdi:string-lights
entity: light.led_controller
name: House
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
animation:
state: 'on'
- type: conditional
conditions:
- entity: timer.house
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.house_timer_percent
- type: vertical-stack
cards:
- type: custom:button-card
icon: mdi:lamp
entity: light.futon_lamp
name: Futon
color_type: icon
state:
- value: 'on'
color: '#FEB90F'
show_state: false
show_label: true
show_icon: true
animation:
state: 'on'
- type: conditional
conditions:
- entity: timer.futon
state_not: idle
card:
type: custom:bar-card
style: |
.card-content {
padding: 0px;
margin-top: -8px;
}
height: 4px
positions:
icon: 'off'
indicator: 'off'
name: 'off'
value: 'off'
entities:
- entity: sensor.futon_timer_percent
Also, here’s an example of a template for creating the timer percentages:
driveway_timer_percent:
unit_of_measurement: "%"
#entity_id: sensor.time
value_template: >
{% set timer = 'driveway' %}
{% if is_state('timer.'~timer,'active') %}
{% set state = states.timer[timer] %}
{% set dur = state.attributes.duration.split(':') %}
{% set dur = ((dur[0]|int)*60+dur[1]|int)*60+dur[2]|int %}
{{ ((dur - (now() - state.last_changed).total_seconds())/dur*100)|int }}
{% else %}
100
{% endif %}