Hi all,
I’d like to create a button that switch on a fan for N minutes and shows the remaining time…
For example if I choose 30minutes the fan starts and the button shows the minutes remaining…
Could someone give to me some suggestion?
Many thanks
I’m trying this code:
# In configuration.yaml
input_select:
fan_time_select:
name: Garage Fan On Time Minutes
options:
- "OFF"
- "30"
- "60"
- "90"
icon: mdi:timer
timer:
fan.timer:
duration: '00:30:00'
automation:
- alias: Update Fan Timer
trigger:
platform: state
entity_id: input_select.fan_time_select
condition:
platform: template
entity_id: input_select.fan_time_select
value_template: "{{ not is_state('input_select.fan_time_select', 'OFF') }}"
action:
- service: switch.turn_on
entity_id: switch.fan_entity_id
- service: timer.start
entity_id: timer.fan_timer
duration: "00:{{ states('input_select.fan_time_select') }}:00"
- alias: Fan Timer Expired
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.fan_timer
action:
- service: switch.turn_off
entity_id: switch.fan_entity_id
- service: input_select.select_option
data:
entity_id: input_select.fan_time_select
option: "OFF"
But I have errors with:
value_template: "{{ not is_state('input_select.fan_time_select', 'OFF') }}"
duration: "00:{{ states('input_select.fan_time_select') }}:00"
I’ve tried with no quote, singol/double quotes but I’ve always error… the same with:
duration: "00:{{ states.input_select.fan_time_select | int) }}:00"
- service: timer.start
data:
entity_id: timer.fan_timer
duration: "00:{{ states('input_select.fan_time_select') }}:00"
When you have anything other than an entity_id in the parameters you need to specify the data section:
The problem remains in the commented code :
automation fan:
- alias: Update Fan Timer
trigger:
platform: state
entity_id: input_select.fan_time_select
condition: []
# platform: template
# entity_id: input_select.fan_time_select
# value_template: '{{ not is_state('input_select.fan_time_select', 'OFF') }}'
action:
- service: light.turn_on
entity_id: light.l_cam_3
- service: timer.start
data:
entity_id: timer.fan_timer
# duration: "00:{{ states('input_select.fan_time_select') }}:00"
- alias: Fan Timer Expired
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.fan_timer
action:
- service: light.turn_off
entity_id: light.l_cam_3
- service: input_select.select_option
data:
entity_id: input_select.fan_time_select
option: "OFF"
input_select:
fan_time_select:
name: Garage Fan On Time Minutes
options:
- "OFF"
- "30"
- "60"
- "90"
icon: mdi:timer
timer:
fan_timer:
duration: '00:30:00'
If I remove the # the code reports error
Change platfom to condition. Take the entity_id line out. It’s not a valid parameter for a template. You also need double quotes around the template because you have single quotes in the template. (You usually will so just get into the habit of using double quotes for templates.) I missed that one the first time!
condition:
condition: template
value_template: "{{ not is_state('input_select.fan_time_select', 'OFF') }}"
Also, try using the minutes parameter for your timer duration.
- service: timer.start
data:
entity_id: timer.fan_timer
duration:
minutes: "{{ states('input_select.fan_time_select') }}"
Perfect, now it works.
Another question…
In lovelace I see the Input select, the status of the timer and the command of the fan (L cam 3)…
I’d like improve the user experience, I wish to see only the status of the L_cam _3, I don’t want the switch…
This is the lovelace code:
type: entities
entities:
- input_select.fan_time_select
- timer.fan_timer
- light.l_cam_3
Many thanks
Could you please post the correct code in a gist please, this sounds very useful!
You just want to see the state of the light, not the physical switch? Like this?
Well, there are a couple of ways to accomplish this.
You can install the template row entity lovelace plugin and template the row.
type: entities
entities:
- input_select.fan_time_select
- timer.fan_timer
- type: custom:template-entity-row
entity: light.l_cam_3
Or you can create a template sensor.
sensor:
- platform: template
sensors:
light_cam3_state:
friendly_name: Light Cam3
icon_template: "{{ 'mdi:lightbulb-outline' if is_state('light.l_cam_3','off') else 'mdi:lightbulb' }}"
value_template: "{{ states('light.l_cam_3') }}"
Then use that in place of the light entity.
type: entities
entities:
- input_select.fan_time_select
- timer.fan_timer
- sensor.light_cam3_state
I recommend the template entity row method because the name, state, icon etc all carry over automatically including the active icon color.
BTW if you declare your lovelace entites as entity objects you can also change the names and icons on the fly.
type: entities
entities:
- entity: input_select.fan_time_select
name: Fan Time
- entity: timer.fan_timer
name: Time Remaining
icon: mdi:fan
- entity: light.l_cam_3
name: My Light
Thanks Again…
So it could be useful for some newbie like me…
This code allows to switch ON for 30-60-90-120 minutes a device (inside configurations.yaml):
automation fan:
- alias: Update Fan Timer
trigger:
platform: state
entity_id: input_select.fan_time_select
condition:
condition: template
value_template: "{{ not is_state('input_select.fan_time_select', 'OFF') }}"
action:
- service: light.turn_on
entity_id: light.l_cam_3
- service: timer.start
data:
entity_id: timer.fan_timer
duration:
minutes: "{{ states('input_select.fan_time_select') }}"
- alias: Fan Timer Expired
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.fan_timer
action:
- service: light.turn_off
entity_id: light.l_cam_3
- service: input_select.select_option
data:
entity_id: input_select.fan_time_select
option: "OFF"
- alias: Timer selecr OFF
trigger:
- platform: state
entity_id: input_select.fan_time_select
to: "OFF"
action:
- service: timer.finish
entity_id: timer.fan_timer
input_select:
fan_time_select:
name: Garage Fan On Time Minutes
options:
- "OFF"
- "30"
- "60"
- "90"
- "120"
icon: mdi:timer
timer:
fan_timer:
duration: '00:30:00'
Thanks for posting this
thanks to all of you for the help, I’m happy if my this could help someone!
now I have all the components but in my opinion is a little bit confused this card:
Basically I’d like to see:
- the “spot” switch on of the fan
- the hourly program
- the status
But the hourly program results “highlighted”… the other parts seem “secondary”, this is the code:title: Accensione Spot Recuperatore
type: entities
entities:
- entity: input_select.fan_time_select
name: Selezionare minuti
icon: 'mdi:menu'
- entity: timer.fan_timer
name: Timer
icon: 'mdi:timer'
- type: 'custom:scheduler-card'
title: Programma orario
include:
- fan
- type: 'custom:template-entity-row'
entity: fan.recuperatore
name: Stato Recuperatore
icon: 'mdi:fan'
That is a card, not an entity row. You have put a card inside a card which is why it looks the way it does.
Try this.
- type: entities
entities:
- entity: input_select.fan_time_select
name: Selezionare minuti
icon: 'mdi:menu'
- entity: timer.fan_timer
name: Timer
icon: 'mdi:timer'
- type: 'custom:template-entity-row'
entity: fan.recuperatore
name: Stato Recuperatore
icon: 'mdi:fan'
- type: 'custom:scheduler-card'
title: Programma orario
include:
- fan
It will now look like two separate cards. If you need them to look like one single card look at the vertical-stack-in-card custom component.
Wherever you have these in your lovelace takes only one card in it’s config. Put them in a vertical stack to get around that.
type: vertical-stack
cards:
- type: entities
entities:
- entity: input_select.fan_time_select
name: Selezionare minuti
icon: 'mdi:menu'
- entity: timer.fan_timer
name: Timer
icon: 'mdi:timer'
- type: 'custom:template-entity-row'
entity: fan.recuperatore
name: Stato Recuperatore
icon: 'mdi:fan'
- type: 'custom:scheduler-card'
title: Programma orario
include:
- fan
If this works and you want to have the “single card look” I mentioned in another post you can change this vertical stack to the custom vertical-stack in card I mentioned earlier.
Perfect, many thanks again!
@enry86cami, I’ve tried to piece together the thread and use what you have posted here, but, I still don’t get my lovelace displaying the timer that I can input 60 minutes and then it sets the timer to turn off something (for me, aircon).
I was wondering if you were able to post all the config that works, for your automations, timer, lovelace, etc. ?
Thanks
Here you are:
automation recuperatore:
- alias: Avvia timer Rec
trigger:
platform: state
entity_id: input_select.fan_time_select
condition:
condition: template
value_template: "{{ not is_state('input_select.fan_time_select', 'OFF') }}"
action:
- service: fan.turn_on
entity_id: fan.recuperatore
- service: timer.start
data:
entity_id: timer.fan_timer
duration:
minutes: "{{ states('input_select.fan_time_select') }}"
- alias: timer rec scaduto
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.fan_timer
action:
- service: fan.turn_off
entity_id: fan.recuperatore
- service: input_select.select_option
data:
entity_id: input_select.fan_time_select
option: "OFF"
- alias: Timer select OFF
trigger:
- platform: state
entity_id: input_select.fan_time_select
to: "OFF"
action:
- service: timer.finish
entity_id: timer.fan_timer
input_select:
fan_time_select:
name: Fan On Time Minutes
options:
- "OFF"
- "30"
- "60"
- "90"
- "120"
icon: mdi:timer
climate_season:
name: Modalità Impianto
options:
- "OFF"
- "ESTATE"
- "INVERNO"
icon: mdi:theme-light-dark
timer:
fan_timer:
duration: '00:30:00'
Thanks for the reply @enry86cami , do you have the lovelace code that you have to execute & display the above timer/automations?
title: Accensione Spot Recuperatore
type: entities
entities:
- entity: input_select.fan_time_select
name: Selezionare minuti
icon: mdi:menu
- entity: timer.fan_timer
name: Timer
icon: mdi:timer
- type: custom:scheduler-card
title: Programma orario
include:
- fan
- type: custom:template-entity-row
entity: fan.recuperatore
name: Stato Recuperatore
icon: mdi:fan