Go in the configuration.yaml file like that? I tried it in mine just like that (well, with my own sensors obviously) and nothing is showing up. I am not getting any errors but am not seeing anything in HA or even in the entities list.
After working with this for a bit, it seems the original script is creating the battery entities for every device except for my Aeotec Door/Window Sensor 6 devices. It lists the battery for even my older First Alert Smoke/CO detectors but not the door/window sensors.
I tried the updated script and when I re-loaded HA, I would initially see the battery devices in the entities list, but by the time HA finished loading fully, they were gone.
@justyns I’m having the same issue with the battery items not showing up if the include is being used or all devices duplicated which aren’t being hidden via customize.
The logs show the settings are being picked up by the component:
Dec 29 13:57:03 homeassistant hass[4275]: 16-12-29 13:57:03 INFO (Thread-3) [custom_components.battery_state] The ‘battery’ component is ready!Include list: [‘sensor.everspring_sm103_doorwindow_sensor_sensor_8_0’, ‘sensor.everspring_sm103_doorwindow_sensor_sensor_9_0’, ‘sensor.fibaro_system_fgms001_motion_sensor_sensor_3_0’]. Exclude list: . Attribute list: [‘battery_level’, ‘battery’]
Which should work since these devices had a _battery item as well once I wasn’t using the include option.
Is it possible to add a group named “group.all_battery_states” and contain a dynamic update of this group within the component, a dynamic group creation in the configuration.yaml seems to be not possible?
Thank you so much for contributing this! You inspired me to finally try out a custom component and it wasn’t difficult at all. Now I just need to learn to actually write the code.
I really like the other comment about turning this into an attribute sensor. Thanks again!
I can’t seem to change the Friendly Name via the customize component. It seems like the Battery Level component overrides any changes you make. I tried deleting this line in the Battery Level component:
@tinglis1 I started on the generic attribute component, but haven’t had time to finish it. I’ll work on it this weekend, and post a PR for it for you to review (or work on if I don’t get that far)
@DuckY1987 I haven’t looked at how to automatically add sensors to a group, but I’ll see if it’s possible since I’d love to have that feature too!
@ciswindell I’m pretty sure the friendly name gets overridden because it is set every time the value is changed. I can probably change how the sensors are being created to fix that, otherwise I’m not sure if I need to look up the customization settings myself. I’ll look into it though; thanks for bringing it to my attention!
@StormStrikes can you check if your Aeotec Door/Window Sensor 6 device has one of the attributes the script is looking for? If it does, I can paste a version of the script with a bunch of debug statements that might give us a better idea why it wouldn’t be picking it up.
Also I realized I haven’t updated my rpi that has zwave on it recently (still has the old sensor id naming scheme), so I’ll do that this weekend and test if mine breaks in the same way as @StormStrikes and @syphernl
Edit: Thanks everyone who’s tested this script out so far, much appreciated!
@tinglis1, @justyns I had a time to create generic attribute sensor with added benefits
What i did was that i took sensor.template, changed the behaviour how to select entities and added some fixed templates.
Features
if you select attribute last_changed or last_triggered and you specify time_format your datetime will get translated to your local timezone and will be formatted like strftime(). Cheatsheet here
if you select attribute battery or battery_level and you don’t specify icon you will get battery icon with fullness ie. mdi:battery-50, mdi:battery-40, mdi:battery-outline etc.
A minor fix for your code after browsing it.
The icon for battery 50% is missing the number for the icon.
There maybe a more elegant way to write that section using rounding and concatenation.
But what you have is functional so I wouldn’t worry unless you are asked to change it when merging with HA.
It can definitely be written more elegant, but as you say it works.
I don’t think this is something to be merged with HA. It’s just a helper not a new component all this can be done using regular sensor.template, this is template sensor for lazy people and for those who like the code clean.
I have corrected missing 50%. If you feel this is usable for more people than here in this thread I can create a special repo and you can contribute.
Nice work, @pilotak! I’ll try it out the next time I update my HA install. I haven’t actually had as much of a need for my original battery script due to the zwave component creating battery_level sensors on its own now, but this is definitely still helpful for non-zwave sensors.
I agree with @tinglis1 that there may be a cleaner method to handle the icon template, but I also wouldn’t worry about it if it’s working for now.
Your example works but gives me multiple sensors with the friendly name battery and no way to know which battery relates to which entities. Anyone good at templating and manage to show the friendly name & battery for each of the specified entities so rather than “battery” it would show “myslipo_1_0 battery” or whatever the friendly name is set to.