Template cover instead of the actual cover in the UI? set position problem

I want to judge the status of the window before opening the cover. If the window is opened, the cover will not be moved, so I added a template cover to replace the actual cover in the UI, but the set position never works. (open and close works well), it says “extra keys not allowed @ data [‘position’]” when set template cover’s position in UI. I think it is a problem of transferring position, The position when the template cover position is clicked should be transferred to the actual cover
HAOS version is 2021.11.4
My code:

cover:
  - platform: template
    covers:
      study_curtain_tpl:
        unique_id: study_curtain_tpl
        friendly_name: study_curtain_tpl
        position_template: "{{ state_attr('cover.study_curtain', 'current_position') | int }}"
        open_cover:
          - service: automation.trigger
            target:
              entity_id: automation.study_cover_open
        close_cover:
          - service: automation.trigger
            target:
              entity_id: automation.study_cover_close
        stop_cover:
          - service: cover.stop_cover
            target:
              entity_id: cover.study_curtain
        set_cover_position:
          - service: automation.trigger
            target:
              entity_id: automation.study_cover_pos
            data:
              position: {{position}}

automation:
  - id: study_cover_open
  # .......
  - id: study_cover_close
  # .......
  - id: study_cover_pos
    alias: study_cover_pos
    trigger:
      - platform: state
        entity_id: input_boolean.test
    action:
      - choose:
          - conditions:
              - condition: state
                entity_id: input_boolean.study_window
                state: 'off'
            sequence:
              - service: 'cover.set_cover_position'
                target:
                  entity_id: cover.study_curtain
                data: 
                  position: {{position}}
          - conditions:
              - condition: state
                entity_id: input_boolean.study_window
                state: 'on'
            sequence:
              - service: persistent_notification.create
                data:
                  message: 'notify something'
        default:
          - service: persistent_notification.create
            data:
              message: 'notify something'

You have a couple single line templates without quotes around them.

tried, also does not work

When you try something out that doesn’t work, please don’t respond with “doesn’t work”. That’s not helpful to the person trying to help you. Post your configuration after you made changes and post the subsequent errors you’re getting in your logs. Lastly, please don’t paraphrase errors. Copy/Paste the entire thing.

On to your issues:

  1. You have 2 single line templates where the template isn’t in quotes. This is the root cause of your initial error.
  2. When you fix 1, you’ll start getting that exact error again when you trigger your automation because you can’t pass variables to an automation through automation.trigger. So your position automation.trigger will error. To fix this, make a script instead of your automation.

Personally, I think you should take a step back and describe your end goal because what you have seems like an over complication. Can you please explain your end goal?

1 Like