Blinds Automation Based on Sensor Entity Value

My basic setup is a thermostat with a 0-100% slider that I poll every 1 second to home assistant via a rest call. I want to use any change in that value to trigger an automation that adjusts the shades to that same value. I have gotten as far as triggering the automation and setting the shades to an arbitrary amount but I am lost on how to get them to open to the value in my sensor entity.

This is what I have so far:

- id: '1671569758008'

  alias: Cybertron Tester

  description: ''

  trigger:

  - platform: state

    entity_id: sensor.distech_blinds_value

  condition: []

  action:

  - device_id: 8382aa3afb25d534e4779dec73502f25

    domain: cover

    entity_id: cover.left_cybertron_shade

    type: set_position

    position: 66

  - parallel:

    - device_id: 93790892a2b8aafab5bf78fd196aba89

      domain: cover

      entity_id: cover.right_cybertron_shade

      type: set_position

      position: 66

If the sensor’s value represents the desired position for the covers, you can reference the State Trigger’s value using trigger.to_state.state

- id: '1671569758008'
  alias: Cybertron Tester
  description: ''
  trigger:
    - platform: state
      entity_id: sensor.distech_blinds_value
  condition: []
  action:
    - service: cover.set_cover_position
      target:
        entity_id:
          - cover.left_cybertron_shade
          - cover.right_cybertron_shade
      data:
        position: '{{ trigger.to_state.state }}'

Reference: Automation Trigger Variables

I implemented that and it successfully moves the shades to the correct percentage with 1 small issue. I need to invert the percentage as mentioned in this WTH thread.

Your original requirement:

get them to open to the value in my sensor entity

However, you actually want:

invert the percentage

So if the sensor’s value is 20 you want to set the cover to 80?

      data:
        position: '{{ 100 - trigger.to_state.state | int(0) }}'

That is a correct assessment of my requirements and that code correctly sets my shades per the indication on the thermostat I was given to integrate. Thank you greatly!

1 Like