Want to update number entity from json payload delivered via webhook

Hi,

I’m trying to create an automation that is triggered by a webhook and updates a number entity based on a field in a json payload.

My utility company sends me a daily email outlining our power usage and I would like to get that data into HA. I have a script that parses the email and sends the web request to HA. That part is working.

I’d like to send something like:

{“usage”: 3, “text”: “On 20240101, we used 3 KWH, which cost us $3” }

I have a notify action that correctly receives and acts on the “text” field of this object. I would like to use the “usage” field to update a number entity

My automation looks like:

alias: Energy set metrics
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - GET
      - POST
    local_only: false
    webhook_id: SuperSecretID
condition: []
action:
  - service: notify.mattermost_support
    data:
      message: "{{ trigger.json.text }}"
  - service: input_number.set_value
    target:
      entity_id: input_number.energy_usage
    data:
      "input_number.energy_usage": "{{ trigger.json.usage }}"
mode: single

When I trigger the webhook, I get this log entry:

Logger: homeassistant.components.automation.energy_set_metrics
Source: helpers/script.py:1783
Integration: Automation (documentation, issues)
First occurred: 6:01:26 PM (1 occurrences)
Last logged: 6:01:26 PM

Energy set metrics: Error executing script. Error for call_service at pos 3: Error rendering data template: Result is not a Dictionary

Unfortunately, my jinja-foo is lacking. What am I missing?

TIA,

Mike.

Change this:

    data:
      "input_number.energy_usage": "{{ trigger.json.usage }}"

To this:

    data:
      value: "{{ trigger.json.usage }}"

Reference

Input Number - Services

Thank you, that fixed it.

Mike.

1 Like