Why does condition value_template work in automation but not numeric_state?

I finally got this automation working:

automation:
 - alias: "Turn on light when movement in living room"
   trigger:
      platform: state
      entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
      to: 'on'
   condition:
    - condition: template
      value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
   action:
    - service: homeassistant.turn_on
      entity_id: script.shutter_living_up

It took hours because I did not now where to start… This experiments leave me with this question to you experts:

Why does this not work:

automation:
 - alias: "Turn on light when movement in living room"
   trigger:
      platform: state
      entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
      to: 'on'
   condition:
     - condition: numeric_state
       entity_id: states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position
       below: 95
   action:
    - service: homeassistant.turn_on
      entity_id: script.shutter_living_up

Script check gives me:
pi@homeautomation:~ $ hass --script check_config

Testing configuration at /home/pi/.homeassistant
17-01-02 15:38:43 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: Entity ID states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position is an invalid entity id for dictionary value @ data['condition'][0]['entity_id']. Got None. (See /home/pi/.homeassistant/configuration.yaml:13). Please check the docs at https://home-assistant.io/components/automation/
Failed config
  automation:
    - action: [source /home/pi/.homeassistant/configuration.yaml:26]
        - entity_id: script.shutter_living_up
          service: homeassistant.turn_on
      alias: Turn on light when movement in living room
      condition: [source /home/pi/.homeassistant/configuration.yaml:21]
        - below: 95
          condition: numeric_state
          entity_id: states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position
      trigger: [source /home/pi/.homeassistant/configuration.yaml:15]
        platform: state
        entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
        to: on

Successful config (partial)
  automation:

But I don’t understand it. I thought the condition gives me True oder False back…

And using data_template instead of value_template yells:

Testing configuration at /home/pi/.homeassistant
17-01-02 15:49:05 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: extra keys not allowed @ data['condition'][0]['data_template']. Got None
not a valid value for dictionary value @ data['condition'][0]['condition']. Got None
required key not provided @ data['condition'][0]['entity_id']. Got None. (See /home/pi/.homeassistant/configuration.yaml:13). Please check the docs at https://home-assistant.io/components/automation/
Failed config
  automation:
    - action: [source /home/pi/.homeassistant/configuration.yaml:23]
        - entity_id: script.shutter_living_up
          service: homeassistant.turn_on
      alias: Turn on light when movement in living room
      condition: [source /home/pi/.homeassistant/configuration.yaml:19]
        - condition: template
          data_template: {{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}
      trigger: [source /home/pi/.homeassistant/configuration.yaml:15]
        platform: state
        entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
        to: on

Successful config (partial)
  automation:

Please enlighten me.

1 Like

It fails because states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position is not an entity_id.

ha! ok. Is this somehow to deduct from the error it gives? I did find nothing that indicates it was a wrog entity_id… Is suppose I’m not deep enough into HASS…

How can I know if an entity works with numeric_state? E.g. states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0?

Does HASS search automatically for the right attribute? The named entity has following attributes:
current_position: 0
friendly_name: living shutter right
node_id: 21

You can use the states dev tool to see a list of valid entity_id’s