Howto create battery alert without creating a template for every device

That looks to happen when there are no battery sensors detected. I’ll have to add a condition to the automation to prevent that.

Can you post a screenshot of the states page for the sensors that aren’t working? I need to see the attributes and entity_id for them to troubleshoot the issue.

Device_class would only need to be set on battery sensors that you create manually. Ones that are created automatically will already have it set.

Most all of my Z-wave devices used to show up with battery levels. Here are the states of one of the Aeotec multisensors.

I wonder if this has something to do with me manually editing entity_registry.yaml to “fix” the z-wave entity naming.

Thanks

image

EDIT: The “device_class: battery” for the .power entity is a remnant–that’s one device_class I Set manually and then deleted, but is still showing…

None of those have battery attributes. Do you have a zwave.xxx entity that corresponds with that device?

Yeah, here’s the zwave.* entity.

There are a bunch with the battery attribute. Here are a few more…


Interesting, there is nothing there that would make me thing it wouldn’t work. Can you try a few things to help isolate where the issue is. First, watch MQTT messages using mosquitto_sub -h MQTT_IP -u MQTT_USERNAME -P 'MQTT_PASSWORD' -v -t 'homeassistant/sensor/#' then force a state change on the multisensor. Let me know if you see any MQTT messages show up. If you don’t see any messages, can you also check to see the last time the “Create Battery Sensor from Attributes” automation was triggered?

Here’s the hass.io output.

core-ssh:~# mosquitto_sub -h MQTT_IP -u MQTT_USERNAME -P 'MQTT_PASSWORD' -v -t ' homeassistant/sensor/#'
Unable to connect (Lookup error.).

I haven’t done any mqtt-related setup for this. Sorry if I missed that…

image

Replace MQTT_IP, MQTT_USERNAME, and MQTT_PASSWORD with the info for your MQTT broker.

The screenshot shows that the automation is being triggered, which is good. Can you confirm that you have MQTT Discovery enabled?

Doh! I do have it enabled via the “Mosquitto broker” addon. Here’s one…

homeassistant/sensor/kitchen_multi_battery/config {
  "device_class": "battery",
  "name": "Kitchen Multi Battery",
  "state_topic": "homeassistant/sensor/kitchen_multi_battery/state",
  "unit_of_measurement": "%",
  "value_template": "{{ value_json.value | int }}",
  "unique_id": "kitchen_multi_battery",
  "json_attributes": [
    "entity_id",
    "attribute",
    "mqtt_config_topic",
    "mqtt_state_topic"
  ]
}
homeassistant/sensor/kitchen_multi_battery/state {
  "value":31,
  "entity_id": "zwave.kitchen_multi",
  "attribute": "battery_level",
  "mqtt_config_topic": "homeassistant/sensor/kitchen_multi_battery/config",
  "mqtt_state_topic": "homeassistant/sensor/kitchen_multi_battery/state"
}

That looks good. Can you confirm you have MQTT discovery enabled? It should look something like below. The most important part is the last 2 lines.

mqtt:
  broker: !secret mqtt_broker_ip
  port: !secret mqtt_port
  client_id: !secret mqtt_client_id
  username: !secret mqtt_username
  password: !secret mqtt_password
  discovery: true
  discovery_prefix: homeassistant

That was it! These two lines were commented out.

Thanks!!

1 Like

i modify my code in the configuration.yaml:

mqtt:
  broker: xxx.xxx.x.xxx
  username: xxxxxx
  password: xxxxxx
  discovery: true
  discovery_prefix: homeassistant

now the battery status is manteined within the restart, but not all of the sensor appear in the home. They need to transmit a status change right?

That’s great to hear. Yes, try forcing a state change on those sensors will make them show up faster. You can also just wait for them to eventually send an update since most battery sensors will eventually send an update, but it can take many hours.

I’m sure you are/have been experiencing ‘scope creep’ on your project but I will be selfish anyway and after thanking you for all your work… I request help debug a little issue I have.
When I include your code according to all instructions, running thru the configuration validation routine I receive the error:

Invalid config for [automation]: required key not provided @ data['action']. Got None
required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/

The error only shows up when I uncomment the “packages: !include_dir_named packages” line. Checking the automations.yaml file shows a blank text file.
( battery_alert.yaml v1.1.1, has.io supervisor version 125, HasOS 1.9, HA 0.75.3, Pi3b+)
The last two lines of the home-assistant.log file shows:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 386, in _get_data
    data = json.loads(response.text.split("'", 1)[1])
IndexError: list index out of range

IIRC, that can cause issues. You need to have at least 1 automation in automations.yaml for automations in packages to load correctly.

That looks unrelated. A quick Google suggests that has something to do with the Google Maps component.

I created a dummy automation in the automation editor.
It works now.
I did receive an error saying mqtt had a problem but that was resolved by putting in the
broker: <local.ip.address> line in configuration.yaml

mqtt:
  broker: 192.168.1.173
  discovery: true
  discovery_prefix: homeassistant

Weird about needing an automation prewritten before your wonderful script.
I’m new with this software. I guess my old habits of coding the foundation before you framed the house isn’t normal protocol anymore… :slight_smile:

Thank you very much for your attention to this matter. You made me smile.

1 Like

do i put this in het battery_alert.yaml or in my custimize.yaml?

homeassistant:
customize:
sensor.sensor_with_battery_attibute:
battery_sensor_creation_disabled: true

customize.yaml

@NotoriousBDG Great work on the package!

I’ve noticed one issue. The groups named group.battery_alert and group.battery_view appeared ok after restart. However, the groups disappear when reloading groups from the configuration screen.

As I’m quite new in the HASS area, I can’t help solve it yet.

HA doesn’t reload packages, you have to restart HA as a whole for it to show up.

1 Like

As an alternative, you could use the new lovelace UI, allows you to modify your ‘groups’ while HA is running. I find Lovelace far better to the old style groups UI bit they started with.