Hello everybody,
I need to send a curl command like this:
curl -i -H "Content-Type: application/json" -X POST -d '{ "days_to_retrieve": 21, "model_type": "KNN", "var_model": "sensor.consumption_w", "sklearn_model": "KNeighborsRegressor", "num_lags": 48, "split_date_delta": "48h", "perform_backtest": "False"}' http://localhost:5000/action/forecast-model-fit
Please note the double quotes, which are correct (both for variable names and variable values, when not a number).
In order to execute the command I’m using the rest_command
integration and I plan to invoke it using an automation, so that I can pass the variable values dynamically if needed (and I do not have to restart the system every time I make a change in the command values).
This is the rest command I wrote in config.yaml:
emhass_forecast_model_fit:
url: http://localhost:5000/action/forecast-model-fit
method: POST
content_type: 'application/json'
payload: '{ "days_to_retrieve": {{ days_to_retrieve }}, "model_type": {{ model_type }}, "var_model": {{ var_model }}, "sklearn_model": {{ sklearn_model }}, "num_lags": {{ num_lags }}, "split_date_delta": {{ split_date_delta }}, "perform_backtest": {{ perform_backtest }} }'
and this is my test automation:
- id: 'forecast_model_fit'
alias: "forecast_model_fit"
description: "forecast_model_fit test"
trigger: []
condition: []
action:
- service: rest_command.emhass_forecast_model_fit
data:
days_to_retrieve: 21
model_type: "KNN"
var_model: "sensor.consumption_w"
sklearn_model: "KNeighborsRegressor"
num_lags: 48
split_date_delta: "48h"
perform_backtest: "True"
mode: single
The problem is with the double quotes that are not passed to the command.
I already tried a lot to escape the quotes but with no success.
Here a couple of logs with my failures:
Using the automation above as it is with simple double quotes:
2023-10-13 01:36:11.247 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://localhost:5000/action/forecast-model-fit. Status code 400. Payload: b'{ "days_to_retrieve": 21, "model_type": KNN, "var_model": sensor.consumption_w, "sklearn_model": KNeighborsRegressor, "num_lags": 48, "split_date_delta": 48h, "perform_backtest": True }'
When I tried to escape \"
:
2023-10-13 01:37:23.259 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://localhost:5000/action/forecast-model-fit. Status code 400. Payload: b'{ "days_to_retrieve": 21, "model_type": \\"KNN\\", "var_model": \\"sensor.consumption_w\\", "sklearn_model": \\"KNeighborsRegressor\\", "num_lags": 48, "split_date_delta": \\"48h\\", "perform_backtest": \\"True\\" }'
Any idea on how I can pass the variable values together with the double quotes?
Thank you!