Hi, i’m trying to make an automation and i think its beyond my capabilitties
The goal is get the xbox game cover currently playing in my dasboard. The xbox and xbox live sensors show when i’m on a game and them the name of the game. With the name i get the id with the api of a web site, and with the id i want to get the cover from the same api and show it in the dasboard.
By now i get the id in a sensor but passing the id to the next step is not working. i have this in my configuration.yaml.
The fist rest_command works well, i have the id in a sensor, but not the second one. My automation at this moment is: (by now only trying to get the url in an input text)
alias: Caratula Juego Xbox
description: Muestra la caratula del juego de xbox que se esté jugando en este momento.
trigger:
- platform: state
entity_id:
- binary_sensor.d13g0_m0nt3s_in_game
from: "off"
to: "on"
condition: []
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}}"
- 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}}"
sorry if i’m doing all wrong but i’m learning every day. Any help will be appreciated.
The sensor shows “unknown”. if I call the service in developers tools with the second rest_command loads the error page of the website. I believe that the template do not add the id to the api url in the second call. But the sensor shows the id correctly. And I test the template and it’s correct, I get the url of the cover.
Not needed according the documentation. If I try the url replacing the sensor with the number directly in a browser works. I suppose because I,m been authorized with the first one
When I click that link (the one that used to be displayed in your post), this is the response:
{"code":401,"error":"Authorization required","message":"You must have an API key to use this resource."}
As an experiment, add apikey to the second URL in the same way it’s used as in the first URL.
EDIT
This seems to be more of an API access problem (composing the correct URL) than a Home Assistant problem. I’m unfamiliar with mobygames API but, for many APIs, it’s often required to include your API key in each individual request.
I replace the sensor.idjuego in the api url with the input_text.idjuego and in developers tools the RESTful Command works ok now. Still “unknow” in the automation. Do not know why with the sensor do not work and works with the input_text. both are the same value…
If you use the first URL with an API key in the browser, the second URL works in the browser without an API key probably because it’s still the same connection session that was established by the first URL. That’s not how REST commands work. Each one is a separate session.
Post the URL you are using that fails to work with the sensor.
In addition, copy-paste the following template into the Template Editor and post the result.
>>>{{ states('sensor.idjuego') }}<<<
Ideally, the result should look like this:
>>>178788<<<
Last question, is sensor.idjuego a Template Sensor?
i post the api key feel free to use and i can get a different one later.
the result is: >>>state: “178788”<<<
the “state:” part should not be there?
EDIT: my mistake, in the sensor template i had: “sensor: {{ states(‘input_text.idjuego’) }}”
First part fixed now, the RESTful Command: trigger_caratula_service in developers tools works but keep receiving “unknow” in the sensor on the automation .
EDIT2: i remove the template from the las restful command and load in the input_text the contente of the variable: Caratula and shows:
{‘content’: {‘code’: 429, ‘error’: ‘Too many requests’, ‘message’: “Oy, you’re making requests too frequently for us to handle. Please wait at least 1.0 seconds between requests.”}, ‘status’: 429}
i suppose that HA is calling the api too fast. I need to make a delay between the two calls, right?
That’s the Input Text, not the Sensor. I need to see the value of sensor.idjuego. Why? Because if the sensor’s value is not 178788 then it will fail to work correctly when used by the REST command’s template.
Also, if sensor.idjuego is a Template Sensor, please post its configuration.
It’s called as fast as you have designed your automation to call it.