How to switch off an appliance

Hi all,

I’m trying to set a sort of “timeout” for an old HiFi, connected via bluetooth with Alexa. I’d like to switch it off in case Alexa is not playing music for a while. I’m using this automation:

alias: Timeout stereo
description: Timeout stereo su echo in pausa
trigger:
  - platform: device
    device_id: a1ee5cde9810197b9d03fe5020e8fb3b
    domain: media_player
    entity_id: media_player.3o_echo_dot_di_davide
    type: idle
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition:
  - condition: device
    type: is_on
    device_id: adb69b05327c1cdbcb33f9b8fea5e1fe
    entity_id: switch.stereo_shelly_1
    domain: switch
action:
  - type: turn_off
    device_id: adb69b05327c1cdbcb33f9b8fea5e1fe
    entity_id: switch.stereo_shelly_1
    domain: switch
mode: single

It works, but I want to set the timeout using a slider in the HA UI. I tried replacing

for:
      hours: 0
      minutes: 10
      seconds: 0

with

for:
      hours: 0
      minutes: '{{states('input_number.stereo_spegnimento_se_echo_in_pausa') | int}}'
      seconds: 0

but I’m getting an error, saying
"Message malformed: expected float for dictionary value @ data['for']['minutes']"

How can I do this?

Thanks

Ciao Polvere,
if you check the template you are using in developer tools - templates, it return you the right number?
Also, do you try it without the comma before the { ?
Instead of this:
minutes: ‘{{states(‘input_number.stereo_spegnimento_se_echo_in_pausa’) | int}}’
This:
minutes: {{states(‘input_number.stereo_spegnimento_se_echo_in_pausa’) | int}}

"{{states('input_number.stereo_spegnimento_se_echo_in_pausa') | int}}"

Try with “” instead of ’ ’

Yes, it does:
image

This is without quotes or anything esle, i.e.:
minutes: {{states(‘input_number.stereo_spegnimento_se_echo_in_pausa’) | int}}

I tried, it doesn’t work either.
I had a look and it seems HA doesn’t access templates inside “for”. But then, I can’t figure out how to get a value from UI in these cases…

What if you add as another condition that the device is idle for 10 mins rather than as a trigger for that time.

I might, but I still need to get that “10 minutes” from a slider in the UI

trigger:
  - platform: state
    device_id: a1ee5cde9810197b9d03fe5020e8fb3b
    domain: media_player
    entity_id: media_player.3o_echo_dot_di_davide
    type: idle
    for:
      hours: 0
      minutes: "{{ states('input_number.for_idle_time') | int }}"
      seconds: 0

Could use state rather than device in trigger. It will allow time.

Replace the time in min with an input_number