Template Sensor for Fibaro Motion Sensors

Hi,
I’m stuck on building a template sensor to show battery-life of Fibaro Motions Sensors (fgms001zw5_motion_sensor). Can anyone guide me on what I’m doing wrong here?

I am serving this from sensor.yaml that I load in configuration.yaml.

  - platform: template
    sensors:
      fibaro_battery:
        friendly_name: "Fibaro Battery Status"
        unit_of_measurement: '%' 
        value_template: '{{ states.zwave.fibaro_system_fgms001zw5_motion_sensor.attributes.battery_level }}'

Thanks in advance,
~Bryan

What is the output of

{{ states.zwave.fibaro_system_fgms001zw5_motion_sensor.attributes }}

in the template editor?

{'node_id': 2, 'node_name': 'FIBARO System FGMS001-ZW5 Motion Sensor', 'manufacturer_name': 'FIBARO System', 'product_name': 'FGMS001-ZW5 Motion Sensor', 'query_stage': 'Complete', 'is_awake': False, 'is_ready': True, 'is_failed': False, 'is_info_received': True, 'max_baud_rate': 40000, 'is_zwave_plus': True, 'capabilities': {'beaming', 'routing'}, 'neighbors': {8, 1}, 'sentCnt': 25, 'sentFailed': 1, 'retries': 0, 'receivedCnt': 39, 'receivedDups': 2, 'receivedUnsolicited': 20, 'sentTS': '2018-06-25 15:01:11:818 ', 'receivedTS': '2018-06-25 15:01:12:665 ', 'lastRequestRTT': 23, 'averageRequestRTT': 23, 'lastResponseRTT': 42, 'averageResponseRTT': 38, 'battery_level': 100, 'wake_up_interval': 7200, 'friendly_name': 'FIBARO System FGMS001-ZW5 Motion Sensor'}

Well, the battery_level attribute is there.

What does

{{ states.zwave.fibaro_system_fgms001zw5_motion_sensor.attributes.battery_level }}

show in the tempate editor?

You could try to make an ‘int’ of it:

{{ states.zwave.fibaro_system_fgms001zw5_motion_sensor.attributes.battery_level | int }}

Do you see the sensor.fibaro_battery sensor in the developer frame (http://ip-address:8123/dev-state)?
If so, what’s the value?

Thanks for your help so far. I am making a little progress.

The sensor finally showed up, but few errors which I’ll post below my code. Basically I believe I had some indenting issues, and then sensor began working. But I tried your approach by adding INT, and see some ‘mappingproxy object’ errors.

  - platform: template
    sensors:
      fibaro_battery:
        friendly_name: "Fibaro Battery Status"
        unit_of_measurement: '%' 
        value_template: '{{ states.zwave.fibaro_system_fgms001zw5_motion_sensor.attributes.battery_level | int }}'
  - platform: template
    sensors:
      fibaro_battery_2:
        friendly_name: "Fibaro Battery Status_2"
        unit_of_measurement: '%' 
        value_template: '{{ states.zwave.fibaro_system_fgms001zw5_motion_sensor_2.attributes.battery_level | int }}'
  - platform: yr

2018-06-25 15:52:53 WARNING (MainThread) [homeassistant.setup] Setup of config is taking over 10 seconds.
2018-06-25 15:54:01 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Fibaro Battery Status, the state is unknown.
2018-06-25 15:54:01 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Fibaro Battery Status_2, the state is unknown.
2018-06-25 15:54:02 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Fibaro Battery Status: UndefinedError: 'mappingproxy object' has no attribute 'battery_level'
2018-06-25 15:54:02 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Fibaro Battery Status: UndefinedError: 'mappingproxy object' has no attribute 'battery_level'
2018-06-25 15:54:05 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-06-25 15:54:09 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Fibaro Battery Status_2: UndefinedError: 'mappingproxy object' has no attribute 'battery_level'
2018-06-25 15:54:10 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template Fibaro Battery Status_2: UndefinedError: 'mappingproxy object' has no attribute 'battery_level'

Thanks again so far.

~Bryan

If the sensor is showing up, you probably don’t need the ìnt`. Just remove it.

Thank you for your help!