Hello, I have an automation and although everything works well, I would like it to be “cleaner” and if the calls to the api do not give any result, I would like to handle it in the best possible way. At the moment when the call to the api does not give any result, the automation does not continue and the input_text and the sensor are not updated or show any error, both keep the last value. and it’s ok for me but I don’t think it is the right way to do it.
The automation is this
alias: Caratula Juego Xbox
description: Muestra la caratula del juego de xbox que se esté jugando en este momento.
trigger:
- platform: state
entity_id:
- sensor.d13g0_m0nt3s_status
condition:
- condition: state
entity_id: binary_sensor.d13g0_m0nt3s_in_game
state: "on"
action:
- service: rest_command.trigger_idjuego_service
data: {}
response_variable: idjuego
- service: input_text.set_value
target:
entity_id: input_text.idjuego
data:
value: "{{idjuego['content']['games'][0].game_id}}"
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: rest_command.trigger_caratula_service
data: {}
response_variable: caratula
- service: input_text.set_value
target:
entity_id: input_text.caratula
data:
value: "{{caratula['content']['cover_groups'][0].covers[0].image}}"
And the api returns when no results found :
{"games":[]}
and when an error occur:
{
"code": 401,
"error": "Authorization required",
"message": "You must have an API key to use this resource."
}
with a different code according the kind the error.
How should I handle not receiving results or a possible error?
Thanks in advance