Template sensor using multiple entities

Hey guys,

I’m trying to add two additianal sensor for smarter status reporting of a poolcover. Can I simply just add the bottom two sensors to the template sensor here? There are comments in the config that should explain what I’m trying to do/understand.

- platform: template
    sensors:
      pool_cover_text_sensor:
        friendly_name: Poolcover
        value_template: >-
          {%- set open = is_state('binary_sensor.pool_cover_open_template_binary_sensor_solid', 'on') -%}
          {%- set closed = is_state('binary_sensor.pool_cover_closed_template_binary_sensor_solid', 'on') -%}
          {%- set opening = is_state('binary_sensor.pc_open_blink', 'on') -%}  ##These are the sensors I'm looking to add
          {%- set closing = is_state('binary_sensor.pc_closed_blink', 'on') -%} ##These are the sensors I'm looking to add
          {%- if open and not closed -%} ##This isn't true anymore since the bottom two sensors need to be accounted for. Would this work? {%- if open and not closed and not closing and not opening -%} 
            Fully Open
          {%- elif not open and closed -%}
            Fully closed
          {%- elif not open and not closed -%}
            Transitioning
          {%- else -%}
            Error - check manually!
          {%- endif -%}

Looks OK to me.

Thanks, this is the line I’m most concerned about {%- if open and not closed and not closing and not opening -%} and if I understand your reply correctly, this would be fine?

Yeah, I think it should work. As long as you’ve selected the entities/states for the additional variables correctly the logic of that line is fine.

1 Like

Thanks again, here is how I think the finished template should look like, would love if someone can check for errors before deployment. Thanks

  - platform: template
    sensors:
      pool_cover_text_sensor:
        friendly_name: Poolcover
        value_template: >-
          {%- set open = is_state('binary_sensor.pool_cover_open_template_binary_sensor_solid', 'on') -%}
          {%- set closed = is_state('binary_sensor.pool_cover_closed_template_binary_sensor_solid', 'on') -%}
          {%- set opening = is_state('binary_sensor.pc_open_blink', 'on') -%}
          {%- set closing = is_state('binary_sensor.pc_closed_blink', 'on') -%}
          {%- set unavailable = is_state('binary_sensor.pool_cover_closed_template_binary_sensor_solid', 'unavailable') -%}
          {%- if open and not closed and not closing and not opening -%}
            Fully open
          {%- elif closed and not closing and not opening and not open -%}
            Fully closed
          {%- elif opening and not closing and not open and not closed -%}
            Opening
          {%- elif closing and not opening and not open and not closed -%}
            Closing
          {%- elif not closing and not opening and not open and not closed -%}
            Sensor read error - check sensors
          {%- elif unavailable -%}
            MCU not responding
          {%- else -%}
            Unknown error - check manually
          {%- endif -%}

Just do it. :wink:

What have you got to lose? it’s easy enough to go back if it doesn’t work as expected.

But it looks OK to me.

Any reason you didn’t model your pool cover as a Template Cover?

1 Like

It’s simply because I’m not on site and can’t easily test it and at the same time trust the results :slight_smile:

@123
I had it as a cover before, but don’t like the way the cover entity fires the action directly when open/close is pressed since this could pontentially lead to accidentally presseing the buttons. I now have separe buttons where dual press is needed for the action to fire.