Hi,
I am new to HA and I have read a lot of stuff but struggling with some of the stuff.
I organized my configuration.yaml (CY) to have different directories for template, themes, sensors, rest-commands because I believe it is more clearly to have single files for stuff that belongs together each in one directory and I do not want a big file with all e.g. sensors in it.
But now the first thing: I recognized that there is a slightly different syntax between configuration.yaml and a single yaml in the above dirs - why?
You have to look carefully on examples / tutorials, is it for CY or for a single yaml.
It is hard for a newbie.
Than the next big big big thing.
I have some self-made stuff (and in the following pihole) which give me back a result as json.
In case of pihole, you can control some stuff by REST and you can have a status by REST.
So I wrote in CY rest_command: !include_dir_merge_named restcommands
Than in that dir I put a yaml with this
pihole_block_off_10:
url: "http***/admin/api.php?disable[...]"
method: post
content_type: "application/x-www-form-urlencoded"
verify_ssl: false
ok, I can now have a Button in UI to set this value, it is working.
In a browser I got back: {"status":"disabled"}
How to deal with the result?
How does the sensor has to look like to give this message out in a card?
(Please remember, I will use a single sensor_pihole_disable.yaml for this)
Like above there is another REST comand to get full status:
{
[...]
"status": "disabled",
"gravity_last_updated": {
"file_exists": true,
[...]
"relative": {
"days": 2,
"hours": 17,
"minutes": 36
}
}
}
And this is my try to get the field status
from status json.
- sensor:
- name: template_custom_pihole_status
unique_id: template_custom_pihole_status
icon: mdi:wall-fire
state: "{{ state_attr('rest_command.pihole_rest_status', 'status') }}"
And for later, I’d like to integrated a self-made component which gives back e.g. S.0.1.1.0
and how do I split this at the points?
I used OpenHAB before, there was an opportunity to look at the raw-result given back in the log-file. I set logger to debug, but it seemed that I do not see the result itself.
I got this but I can not see the raw result elsewhere:
2023-01-14 09:43:35.143 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [...] Received {'type': 'call_service', 'domain': 'rest_command', 'service': 'pihole_block_off_10', 'target': {}, 'service_data': {}, 'id': 33}
2023-01-14 09:43:35.144 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=rest_command, service=pihole_block_off_10, service_data=>
2023-01-14 09:43:35.149 DEBUG (Recorder) [homeassistant.components.recorder.core] Processing task: EventTask(event=<Event call_service[L]: domain=rest_command, service=pihole_block_off_10, service_data=>)
2023-01-14 09:43:35.308 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: http***/admin/api.php?disable[...]. Status code: 200. Payload: None
Amd also a big mystery is the difference between template (template-sensor and sensor-template) and seinsor(s). Can someone explain clearly?
Regards and thanks