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

Error rendering data template: UndefinedError: 'dict object' has no attribute 'json' when trying to run Kindle battery blueprint #75

Open TomAnks opened 11 months ago

TomAnks commented 11 months ago

Not sure what I am doing wrong here, but I am receiving the above error when trying to run the automation to fetch the battery level of the Kindle.

I have:

This means that I am unable to run the automation as it errors every time. Can anyone assist?

sibbl commented 11 months ago

Hey,

thanks for the feedback. I don't use the webhook myself, so I cannot directly assist and test it.

However, I took a guess how to fix it. I would appreciate if you could verify the change by using the following blueprint:

Direct Blueprint URL: https://github.com/sibbl/hass-lovelace-kindle-screensaver/blob/8778b4103e498f76d024e5791504ae023f21fd15/battery_sensor_blueprint.yaml

HA import link of this Blueprint: https://my.home-assistant.io/redirect/blueprint_import/?blueprint_url=https%3A%2F%2Fgithub.com%2Fsibbl%2Fhass-lovelace-kindle-screensaver%2Fblob%2F8778b4103e498f76d024e5791504ae023f21fd15%2Fbattery_sensor_blueprint.yaml

TomAnks commented 11 months ago

Thank you! The new blueprint gave me the following error:

Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'query'

So I am still unable to pull the battery life from the Kindle into HA.

TomAnks commented 11 months ago

Hi, I have gone through the setup again and ensured that the batteryLevel code is correct on my Kindle, but I am still encountering the same error. Do you have any other ideas for what could be the fix?

TomAnks commented 11 months ago

Hi! I managed to get the battery level webhook to update the input_value once by setting up a new automation:

alias: Kindle - Battery Level
description: Battery level for Kindle dashboard
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: set_kindle_battery_level
condition: []
action:
  - service: input_number.set_value
    data: "{{ trigger.json.batteryLevel }}"
    target:
      entity_id: input_number.kindle_battery_level
mode: single

kindle battery

But then the automation stopped updating and went back to returning the same error as above :/

Edit: It looks like it might be updating now. I was trying to test the automation rather than letting the webhook receive a payload, and that was causing it to error.

scarolan commented 5 months ago

I tried @sibbl 's updated blueprint but still seeing kindle_battery_level is always 0 and never gets updated.

Fetching images is working fine.

Rendering http://homeassistant.local:8123/z-kindle-e-ink/0 to image...
Converting rendered screenshot of http://homeassistant.local:8123/z-kindle-e-ink/0 to grayscale png...
Finished http://homeassistant.local:8123/z-kindle-e-ink/0
2024-01-14T19:59:27.136Z: Image 1 was accessed

update.sh has this in it:

if [ 1 -eq $CONNECTED ]; then
    batteryLevel=`/usr/bin/powerd_test -s | awk -F: '/Battery Level/ {print substr($2, 0, length($2)-1) - 0}'`
    isCharging=`/usr/bin/powerd_test -s | awk -F: '/Charging/ {print substr($2,2,length($2))}'`
    if wget -q "$IMAGE_URI?batteryLevel=$batteryLevel&isCharging=$isCharging" -O $TMPFILE; then
        mv $TMPFILE $SCREENSAVERFILE
        logger "Screen saver image updated"

and my automation is the same as the one @TomAnks created. (webhook_id obfuscated)

alias: Kindle - Battery Level
description: Battery level for Kindle Weather Display
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: false
    webhook_id: 7AA751FBRANDOMHEX9ABCDEFGA85
condition: []
action:
  - service: input_number.set_value
    data: "{{ trigger.json.batteryLevel }}"
    target:
      entity_id: input_number.kindle_battery_level
mode: single

I tried turning local_only to false but that didn't seem to help either.