Howto create battery alert without creating a template for every device

The notifier is setup to my Apple iPhone devices which do not require any special format for the alert content.

Which notifier component are you using? Do you see any errors in the log when the automation fires?

It looks like it is working now. I adjusted the max alert threshold and it now is sending notifications to my iphones.

I’m not sure why changing the threshold fixed the issue.

Anyway, I appreciate the battery alert piece and will definitely be using it going forward.

Regards

1 Like

Edit: never mind the below statement. After upgrading, everything is working as before. The Check my Configuration add-on must have triggered on something else. Sorry for causing alarm without proper cause.

Could it be that the package is incompatible with HA 0.87 ? I ran Check My Configuration before updating from 0.86.4 to 0.87, but it says something is wrong here. Maybe this has something to do with this breaking change (but I might be jumping to conclusions :-)):

“MQTT platforms will now flag mistyped configs from configuration.yaml correctly as invalid, instead of just ignoring them. (@emontnemery - #20562) (mqtt docs ) (breaking change)”

alias: battery_notification_slack
      hide_entity: False
      initial_state: True
      trigger: ?
        - platform: time
          at: 10:00:00
        - platform: time
          at: 18:00:00
        - platform: state
          entity_id: ?
            - input_number.battery_alert_threshold_min
            - input_number.battery_alert_threshold_max
    - action: ?
        - data_template: ?
            payload: <homeassistant.helpers.template.Template object at 0x7fbeb52b4668>
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb52b44a8>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb52b4ac8>
          service: mqtt.publish
        - data_template: ?
            payload: <homeassistant.helpers.template.Template object at 0x7fbeb52acc50>
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb52ac5f8>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb52ac160>
          service: mqtt.publish
        - data_template: ?
            payload: <homeassistant.helpers.template.Template object at 0x7fbeb529b7f0>
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb529b470>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb529bd68>
          service: mqtt.publish
      alias: battery_sensor_from_attributes
      condition: ?
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52ac860>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52acc88>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52ac4a8>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb5302da0>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52f0f98>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb529b358>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb529b828>
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb528d860>
        - condition: or
          conditions: ?
            - condition: template
              value_template: <homeassistant.helpers.template.Template object at 0x7fbeb529b278>
            - condition: template
              value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52acd30>
            - condition: template
              value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52b4438>
      hide_entity: False
      initial_state: True
      trigger: ?
        - platform: event
          event_type: state_changed
    - action: ?
        - data_template: ?
            entities: <homeassistant.helpers.template.Template object at 0x7fbeb529c6a0>
            object_id: <homeassistant.helpers.template.Template object at 0x7fbeb528d390>
          service: group.set
      alias: update_battery_status_group_members
      hide_entity: False
      initial_state: True
      trigger: ?
        - platform: homeassistant
          event: start
        - platform: time_pattern
          minutes: /5
          seconds: 0
    - action: ?
        - data_template: ?
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb52b4cf8>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb52b4f60>
          service: mqtt.publish
        - data_template: ?
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb52b4cc0>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb52b4048>
          service: mqtt.publish
        - data_template: ?
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb52b4dd8>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb52b4b38>
          service: mqtt.publish
        - data_template: ?
            retain: <homeassistant.helpers.template.Template object at 0x7fbeb52b4da0>
            topic: <homeassistant.helpers.template.Template object at 0x7fbeb533c240>
          service: mqtt.publish
      alias: delete_battery_sensor
      condition: ?
        - condition: template
          value_template: <homeassistant.helpers.template.Template object at 0x7fbeb52b4710>
      hide_entity: False
      initial_state: True
      trigger: ?
        - platform: state
          entity_id: ?
            - input_text.delete_battery_sensor

Release 1.2.2 is available.

Added

  • Alert if battery state is unavailable

Removed

  • Removed startup trigger from automation.update_battery_status_group_members

Changed

  • Default to notify.notify if input_text.notifier_name doesn’t contain “notify.”

Might be helpful to add a link to the latest release from the original post, as it’s easy to get lost in this huge thread.

I would have long ago if it was possible. That post is not editable anymore.

1 Like

@NotoriousBDG I have deleted this package, deleted ha database, and deleted mqtt database, recreated clean ha docker container, and still I find those .battery sensors…
How to completley remove those?

1 Like

Deleting the package, deleting the MQTT database, then restarting is enough to remove it.

Actualy this works… I just forgot I have 2 mqtt servers (cloud and local). After deleting both db, sensors dissapered.

1 Like

Any idea what mite be causing the following errors?

2019-02-17 21:20:14 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.battery_sensor_from_attributes. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 380, in action
    await script_obj.async_run(variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 131, in async_run
    await self._handle_action(action, variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action
    action, variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service
    context=context
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE], variables))
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 60, in render_complex
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 60, in <dictcomp>
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 61, in render_complex
    return value.async_render(variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 140, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 23, in top-level template code
TypeError: object of type 'NoneType' has no len()
2019-02-17 21:25:22 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.battery_sensor_from_attributes. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 380, in action
    await script_obj.async_run(variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 131, in async_run
    await self._handle_action(action, variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action
    action, variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service
    context=context
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE], variables))
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 60, in render_complex
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 60, in <dictcomp>
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 61, in render_complex
    return value.async_render(variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 140, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 23, in top-level template code
TypeError: object of type 'NoneType' has no len()
2019-02-17 21:25:53 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.battery_sensor_from_attributes. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 380, in action
    await script_obj.async_run(variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 131, in async_run
    await self._handle_action(action, variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action
    action, variables, context)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service
    context=context
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 76, in async_call_from_config
    config[CONF_SERVICE_DATA_TEMPLATE], variables))
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 60, in render_complex
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 60, in <dictcomp>
    for key, item in value.items()}
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 61, in render_complex
    return value.async_render(variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 140, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 23, in top-level template code
TypeError: object of type 'NoneType' has no len()

@NotoriousBDG

Just deleted the database and restarted HA and get the following error:

2019-02-17 21:52:01 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.update_battery_status_group_members. Invalid data for call_service at pos 1: Entity ID is an invalid entity id for dictionary value @ data['entities']

Interesting. Can you check on your states page for any entities that have a battery_level, battery, or ‘battery numeric’ attribute with an null value?

The latest version of the package should prevent that from happening on startup, but it may still happen if you have no battery sensors.

I do have one “battery_level: null” on the states page.

I am using the latest version “1.2.2”

That’s what’s causing the issue. Is that a sensor you’d want to be alerted on or would you rather ignore it?

It’s not needed, It isn’t a permanent device, it’s created from google maps device tracker and changes often.

@NotoriousBDG
I discovered the following when the battery one of my Fibaro Smoke Sensor ( FGSD-002 ), went empty, and the smoke sensor lost contact with HA., the HA sensors state became "initializing" and “unknown”, the battery level attribute was set to 100%.

Meaning, your package battery level sensor displaying 100% for a device which is not connected to HA.

This should be fixed in the 1.2.3 release.

1 Like

Can you provide some screenshots of the sensor on the states page?

Release 1.2.4 is out now, which adds support for battery_critical attributes courtesy of @Djebouh.

Thanks @djebouh!

3 Likes