sibbl / hass-lovelace-kindle-screensaver

This tool generates a png from a Home Assistant Lovelace view, which can be displayed on a Kindle device which has the Online Screensaver plugin installed.
MIT License
311 stars 71 forks source link

Can't get battery status using your own kindle 4 setup guide #35

Closed aptonline closed 2 years ago

aptonline commented 2 years ago

I've managed to setup everything via your setup guide (not using the online screensaver extention) except for the battery status. From the description in the guide it reads like the battery status is ONLY available via the online screensaver extension (via an edited file), is this correct or should I be able to get the battery status via either method.

aptonline commented 2 years ago

the automation in HA seems to be failing with:

Stopped because an error was encountered at 7 May 2022, 20:10:49 (runtime: 0.02 seconds)

Error rendering data template: UndefinedError: 'dict object' has no attribute 'json
sibbl commented 2 years ago

@aptonline indeed the battery reporting feature was added by a community member only in this repo and only some patching instructions for the onlinescreensaverplugin were documented: https://github.com/sibbl/hass-lovelace-kindle-screensaver#patch-for-kinde-online-screensaver

So yes, this needs some additions in the script.sh of the special adaptation of the plugin for the Kindle 4.

Without having tested it, I think this might already work:

- DOWNLOADRESULT=$(wget -q "$IMAGE_URI" -O $TMPFILE)
+ DOWNLOADRESULT=$(wget -q "$IMAGE_URI?batteryLevel=$CHECKBATTERY&isCharging=$IS_CHARGING" -O $TMPFILE)

Please also update your rendering Docker container as I just added support for the $IS_CHARGING values which should be 0 and 1 (instead of the previously solely supported Yes and No values from a different source).

Maybe you can give it a try and give me some feedback whether this worked for you already? Thanks a lot!

aptonline commented 2 years ago

Thanks I’ll give it try and report back 👍

aptonline commented 2 years ago

Ok so the good news in the battery percentage is working after editing script.sh and updating the docker container. The charging status however is not updating as expected.

aptonline commented 2 years ago

Oh so an update on the battery percentage. How often should this be updated, on every webhook call or only when there is a battery change? In the docker logs I’m only seeing 4 initial battery updates since I implemented the changes and nothing overnight.

sibbl commented 2 years ago

@aptonline the Kindle device includes its battery percentage into each HTTP request when retrieving the image. These parameters are then forwarded to HA whenever they changed. I might be possible that the device wasn't awake too long and couldn't read the battery percentage from its hardware.

Maybe you can check the on device log whether the battery changes were present there? If so and you say they weren't sent to the image renderer and thus to HA, then we might have a bug somewhere.

aptonline commented 2 years ago

I’ll tweak the setting and she what happens. Also trying @lanrat’s fork to see how they compare.

SurfingSpider commented 2 years ago

I am also having trouble with this. I have it setup and running on a kindle 4. I just cant get Battery updates to work. I have updated the script.sh and can see entries for charging / battery in the logs.

It took me a while to work out I had to add to add a new ENV Variable to my docker. But now I get the Battery %.

What I am unclear on is how to change the....

"Please also update your rendering Docker container as I just added support for the $IS_CHARGING values which should be 0 and 1 (instead of the previously solely supported Yes and No values from a different source)."

I am sorry I don't understand where I need to change this.

Could you please point me in the right direction.

sibbl commented 2 years ago

HI @SurfingSpider,

the comment you quoted does not require any further action if you've just pulled your docker container. It was just a hint that I've changed something in the Docker container to support this line, so the Docker container had to be updated if created before my comment.

"Please also update your rendering Docker container as I just added support for the $IS_CHARGING values which should be 0 and 1 (instead of the previously solely supported Yes and No values from a different source)."

So only the change in the script.sh is necessary. But keep in mind that it's untested, so I'd appreciate any feedback. If it's working, I can add this line to the main repository so this issue can be closed. I couldn't find the time to test this yet, especially since my Kindle is plugged in all the time.

SurfingSpider commented 2 years ago

Sods law it started working after leaving it for the next automated refresh. Thank you for getting back to me though. It is all working now.

sibbl commented 2 years ago

Thanks for the confirmation! I've added the diff mentioned above to the README of this plugin, so we have both the onlinescreensaver and the custom Kindle 4 extension covered.