Using Input_select in automation - action

I am trying to use input select to choose which camera i pan…cant figure this out…

without the input_select, for individual camera, this works. it will pan ‘camone’ accordingly ;

panright:
  sequence:
  - service: onvif.ptz
    entity_id: camera.camone
    data:
      pan: RIGHT
      zoom: ZOOM_IN
      distance: 0.1
      speed: 0.5
      continuous_duration: 0.5
      preset: 1
      move_mode: ContinuousMove

So i wanna be able to select which camera that i pan (either camone or camtwo). input_select.cctvlist is either ‘camone’ or ‘camtwo’.
But the one below doesnt work. How can i achieve this?

cctvlist:
  name: CCTV List
  options:
    - camera.camone
    - camera.camtwo
  initial: camera.camone
panright:
  sequence:
  - service: onvif.ptz
    entity_id: input_select.cctvlist
    data:
      pan: RIGHT
      zoom: ZOOM_IN
      distance: 0.1
      speed: 0.5
      continuous_duration: 0.5
      preset: 1
      move_mode: ContinuousMove

Try

  - service: onvif.ptz
    data:
      entity_id: "{{ states('input_select.cctvlist') }}"

So i indent everything else like this? *edit: tried this, didnt work

panright:
  sequence:
  - service: onvif.ptz
    data:
      entity_id: "{{ states('input_select.cctvlist') }}"
        data:
          pan: RIGHT
          zoom: ZOOM_IN
          distance: 0.1
          speed: 0.5
          continuous_duration: 0.5
          preset: 1
          move_mode: ContinuousMove

Eh, no :wink:

Just that one line moved, nothing else. Just the one data:

panright:
  sequence:
  - service: onvif.ptz
    data:
      entity_id: "{{ states('input_select.cctvlist') }}"
      pan: RIGHT
      zoom: ZOOM_IN
      distance: 0.1
      speed: 0.5
      continuous_duration: 0.5
      preset: 1
      move_mode: ContinuousMove

You rocks! it works. I will nvr figure out how the code works myself. lol.

So, here’s how I worked it out:

  1. Looked at what the service expects in the data: block (aka Service data) and noted that entity_id is expected/valid in there. Experience tells me that often it’s also valid outside that, however…
  2. Templating takes place in the service and data sections (and in other places where explicitly mentioned in the docs). That means that to have your template for entity_id parsed, it needs to be in the data section.

Unfortunately point (2) is no longer clearly called out in the docs, so it’s not obvious to newcomers.

Yes, that s what i have trouble figuring out. I couldnt understand the structure. i notice that entity_id is on the same level (indent?) of the service calls, while the rest “pan data” is one level below (indented) the service call. I’d nvr figure out that entity_id can be of the same level (indent) of the pan data.

Most of the times, i need to find the codes (examples on the net) that matches what i wanna do, and then just replace the code line by line accordingly. Once it isnt of the same structure, i ll be lost.

Yeah, getting your head around yaml structure is a must for these things. Yaml structure is not specifically a homeassistant thing, but homeassistant uses yaml for configuration so you’re going to need it.

It’s basically:

key:
  option1: value1
  option2:
    - list_value1
    - list_value2

So in your script you have sequence, and then each thing you want to do listed.

Each thing you want to do has a service, and then some data that defines how the service acts

sequence:
  - service: THE SERVICE YOU WANT TO RUN FIRST 
    data:
      option1: YOUR FIRST SERVICE OPTION
      ETC
  - service: THE NEXT SERVICE YOU WANT TO RUN
    data:
      option1: YOUR SECOND SERVICE OPTION

Thusly, if you want to turn a light on to 20%, wait 20 seconds, then turn a switch on, you will use:

  • the light.turn_on service with data of which light and the brightness level
  • the delay service with the seconds option set to 20
  • the switch.turn_on service with the data being which switch

Which looks like this:

sequence:
  - service: light.turn_on
    data:
      entity_id: light.bed_lamp
      brightness_pct: 20
  - delay:
      seconds: 20
  - service: switch.turn_on
    data:
      entity_id: switch.heater
1 Like