Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TomAnks opened this issue Jul 27, 2023 · 5 comments

Comments

@TomAnks
Copy link

TomAnks commented Jul 27, 2023

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:

  • Applied the Kindle Online Screensaver patch
  • Created 2 new entities: input_number.kindle_battery_level and input_boolean.kindle_battery_charging
  • Imported the blueprint file from the instructions.
  • Added the 2 new entities to the blueprint
  • Set the webhook to equal the same as that defined in the add-on config.

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

@sibbl
Copy link
Owner

sibbl commented Jul 28, 2023

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
Copy link
Author

TomAnks commented Jul 28, 2023

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
Copy link
Author

TomAnks commented Jul 30, 2023

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
Copy link
Author

TomAnks commented Aug 3, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants