Get attribute in template sensor

Hi

I can’t get my template sensor to work with my vacuum.roomba, it seems to be a pretty basic thing but I just cant do it :frowning:

I got the code below and whatever i try it always says “offline” even though the “bin_full” actually says ‘true’ if I check the attribute in the states section.

- platform: template
    sensors:
      roomba_bin_state_template:
        friendly_name: 'Cleos behållare'
        value_template: >-
          {% if is_state('states.vacuum.roomba.attributes.bin_full', 'false') %}
              OK
          {% elif is_state('states.vacuum.roomba.attributes.bin_full', 'true') %}
              Full
          {% else %}
              Offline
          {% endif %}

Should be: is_state_attr('states.vacuum.roomba','bin_full', 'true') :slight_smile:

1 Like

still only showing “offline” :frowning:
now it looks like this

  - platform: template
    sensors:
      roomba_bin_state_template:
        friendly_name: 'Cleos behållare'
        value_template: >-
          {% if is_state_attr('states.vacuum.roomba','bin_full', 'true') %}
              Full
          {% elif is_state_attr('states.vacuum.roomba','bin_full', 'false') %}
              OK
          {% else %}
              Offline
          {% endif %}
1 Like

Sorry about that :slight_smile:
Did not have enough coffee before my reply :wink:

is_state_attr('vacuum.roomba','bin_full', 'true') will work better :slight_smile:

sorry but it does not work, feels like we are so close! :cry:

now the code looks like this

  - platform: template
    sensors:
      roomba_bin_state_template:
        friendly_name: 'Cleos behållare'
        value_template: >-
          {% if is_state_attr('vacuum.roomba','bin_full', 'true') %}
              Full
          {% elif is_state_attr('vacuum.roomba','bin_full', 'false') %}
              OK
          {% else %}
              Offline
          {% endif %}

Get more coffee :smiley:

is there some way to run the command to check if it works directly?

somehing like this: echo is_state_attr(‘vacuum.roomba’,‘bin_full’)

totally wrong but you get the idea

I got the original code from here: https://github.com/jtscott/hass-config/blob/master/sensor/roomba.yaml

but it seems that code doesn’t work anymore

Yes paste it in dev-templates :wink:

It could be the attribute is a boolean, not a string. So maybe:

is_state_attr('vacuum.roomba','bin_full',true)

You can see if this works if you put this in the template editor:

{{ is_state_attr('vacuum.roomba','bin_full',true) }}
2 Likes

That was the problem! THANKS to both of you, I finally got it working!

Also the dev-templates are pretty nifty :slight_smile: Damn I love hassio! :smiley:

1 Like