See if someone can help me with this:
Scenario: Raspberry Pi 3B + HA (supervisor) + HomeBridge + AppleTV.
Version: Home Assistant 0.114.4
I wanted to create a command_line (or more suitable) for a script (python) to run that gets a list of names.
Python name file: who_at_home.py (path /config/script/)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
print( {"Enrique": True, "Carmen": False})
Show these names in a dictionary / JSON based HA template {Name: Property}
Enrique: True
Carmen: False
Expose the entity that executes the script through the HA REST API (I already have it operational and working, which is the REST API, activation of tokens, etc). But I don’t know the structure of the URL to consult the data and that it is returned in JSON. Maybe with json_attributes?
I would also be interested in showing that information in Home Apple as a list (it would be similar to the template). I suppose that if done right in HA it would already be replicated in Home Apple … Is that right?
Then using Siri Shortcuts I would like to consume said endpoint (I know how to do this).
Could someone help me with this? Any similar example?
sensor:
- platform: command_line
name: Who at Home
json_attributes:
- Enrique
- Carmen
command: 'python3 /config/scripts/who_at_home.py'
value_template: '{% set value_json = value|from_json %}{{ value_json.state }}'
scan_interval: 10
command_timeout: 120
- platform: template
sensors:
who_at_home_tempp:
friendly_name: 'who_enrique'
value_template: {{ value_json.Enrique }}'
All help is good.
Thank you very much!