Howto create battery alert without creating a template for every device

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.

Any nice way to put the generated group(s) in the lovelace UI? The entities card needs the entities listed in the config right?

2 Likes

OT: I don’t use join for my Shield but I do use tasker and mqtt client and autoinput. This way I can report the current app (source) for my shield and use that to refresh my universal remote tablet with apps like Yatse, Android TV remote, Fully Kiosk, Google Play Music etc. How do you plan on using Join? And have you discovered the ring phone feature yet?

@NotoriousBDG thanks for your continued improving of this package. Maybe you could update OP with the link to your github for newbies to this thread?

I got over excited about Join when I saw the API. I made an incorrect assumption that i could use the API to send tasker commands. Which in turn would allow me to use google assistant to say things like “Ok Google, Open netflix on shield” and it would work. I really just want an API on the Shield that can open apps and report the current app. I guess as a developer by trade i can write one but was hoping for something out of the box

I would have updated the OP long ago if I could. Unfortunately, it’s no longer editable.

@ NotoriousBDG love your work, but I am facing an issue getting some sensor not to show. I have few sensors that have battery in their name and I tried to use:

battery_sensor_creation_disabled: true
battery_alert_disabled: true

that is not working for me. I have read the entire thread to find a solution and tried many I saw but none worked for me. here are some snapshots to show what I mean:

my custmize.yaml:

sensor.neo_coolcam_battery_powered_pir_sensor_alarm_type_3:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_alarm_type_2:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_burglar_2:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_alarm_level:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_alarm_type:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_burglar:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_luminance:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_sourcenodeid:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_alarm_level_3:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_alarm_level_2:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_luminance_2:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_sourcenodeid_2:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_luminance_3:
battery_sensor_creation_disabled: true
battery_alert_disabled: true
sensor.neo_coolcam_battery_powered_pir_sensor_sourcenodeid_3:
battery_sensor_creation_disabled: true
battery_alert_disabled: true

as you can see the attribute is set correctly on the entities but they still show up. no mqtt for those, and I even deleted the mqtt db file (I use mosquitto) and restarted so many times already.
thanks for the help to fix this.