Hi there, thanks for reading!
I’m trying to do the following:
from another system I send a:
curl --header "Content-Type: application/json" \
--request POST \
--data ‘{“heartbeat”:{“monitorID”: 9, “status”: 0}}’ \
http://homeassistant.local:8123/api/webhook/somewebhookid
which ultimately should change the status of the entity person.john to away when status is 0 and home when status is 1.
I can’t seem to understand how to do it. I am able to save the status from the webhook to an input:
alias: Pixel Ping
description: Get information from Uptime Monitor
trigger:
- platform: webhook
webhook_id: "somewebhookid"
action:
- service: input_number.set_value
data:
value: "{{ trigger.json.heartbeat.status }}"
target:
entity_id: input_number.pixel_status
enabled: true
mode: single
but that’s about it. I can’t seem to get how to 1) convert the status from 0 and 1 to “away” and “home” and 2) save this as state for person.john.
Please help! I’m not that new to HA and I am a programmer, but I can’t seem to understand how to achieve my goal even after reading the documentation thoroughly a healthy amount of times.
Best regards
I have to reply to myself, but in case anyone want to do the same:
You can save the result in an input that you can define in the helpers - I created one with options “Home” and “Away” and manipulate it from the automation by calling an action type call service → input select set options.
service: input_select.set_options
data:
options: |
{% if trigger.json.heartbeat.status == 0 %}
Away
{% elif trigger.json.heartbeat.status == 1 %}
Home
{% endif %}
target:
entity_id: input_select.pixel_status
But because ultimately I wanted to change the state of a device, I went with:
service: device_tracker.see
data:
dev_id: pixel_7_pro_ping
location_name: |
{% if trigger.json.heartbeat.status == 0 %}
Away
{% elif trigger.json.heartbeat.status == 1 %}
Home
{% endif %}
This is not ideal, because when I try to manipulate the real device, which is called
device_tracker.pixel_7_pro in which case I add to the dev_id: pixel_7_pro, it doesn’t change the device state. By calling it pixel_7_pro_ping, HA creates an entity device_tracker.pixel_7_pro_ping, which I add in my user as a device to track, and thus whenever the status of device_tracker.pixel_7_pro_ping changes to Home or Away, the status of the person changes as well.
Not sure if the explanation was good enough to follow, but if you are trying to accomplish something similar, just write me.