-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't start container via rest template since HA 2023.6 #127
Comments
Same problem |
I get the same error |
Thanks for reporting. There might have been a change to the rest sensor in home assistant. I vaguely remember talking about it on a podcast episode recently, but could be mistaken. I am using MQTT discovery via the |
Log: Logger: homeassistant.components.rest.switch Error while switching off http://local.ip:8126/container/frigate Not sure that's particularly helpful? |
Thanks @mitchellross I can see the same for me at the moment. The server I'm testing with doesn't seem to be working at all for me at the moment (even via Postman) so need to do a bit further digging. I changed the command to use webhook.site. I suspect Home Assistant is posting the data raw, and not in the same way it used to (ie JSON or HTTP post fields) The hunt continues for the moment |
Thanks Phil. Luckily its still reporting state fine to HA, so we can use a workaround for the moment with rest_commands and a script that turns off when state is on and vice versa.
Eg.
rest_command:
temp_frigate_on:
url: http://local.ip:8126/container/frigate/start
temp_frigate_off:
url: http://local.ip:8126/container/frigate/stop
and script:
alias: Temp frigate switch
sequence:
- choose:
- conditions:
- condition: state
entity_id: switch.frigate
state: "on"
sequence:
- service: rest_command.temp_frigate_off
data: {}
- conditions:
- condition: state
entity_id: switch.frigate
state: "off"
sequence:
- service: rest_command.temp_frigate_on
data: {}
mode: restart
|
Have nailed this down to Home Assistant no longer sending the 2023.5 curl -X 'POST' 'http://192.168.1.x:8126/container/xxx' -H 'connection: close' -H 'content-type: application/octet-stream' -H 'content-length: 18' -H 'accept-encoding: gzip, deflate' -H 'accept: */*' -H 'user-agent: HomeAssistant/2023.5.4 aiohttp/3.8.4 Python/3.10' -H 'host: 192.168.1.x' -d $'{"state": "start"}' 2023.6 curl -X 'POST' 'http://192.168.1.x:8126/container/xxx' -H 'connection: close' -H 'content-length: 18' -H 'user-agent: HomeAssistant/2023.6.1 httpx/0.24.1 Python/3.11' -H 'accept-encoding: gzip, deflate, br' -H 'accept: */*' -H 'host: 192.168.1.x' -H 'content-type: ' -d $'{"state": "start"}' This could be a bug introduced when moving from aiohttp to httpx, which was done in this PR: home-assistant/core#90768
I'll raise this as an issue in Home Assistant core and see what the Home Assistant devs think here. There might be other REST sensors/switches etc that are now broken/unsupported. If the devs decide on that side they won't put a change in, then I'll update HA-Dockermon to be compatible with 2023.6 moving forward. |
2023.6 Workaroundswitch:
- platform: rest
resource: http://192.168.1.x:8126/container/xxx
name: XXX Test
body_on: '{"state": "start"}'
body_off: '{"state": "stop"}'
is_on_template: '{{ value_json is not none and value_json.state == "running" }}'
headers:
content-type: 'application/octet-stream' Seems the |
Workaround works indeed, I tried it indeed like that before, but probably, like you said, it had wrong capitalized casing. |
Thanks much @philhawthorne, this works fine |
My automations using ha-dockermon and rest switch work back again, thx @philhawthorne |
Same problem and also error in the HomeAssistant log: ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json is not none and value_json.state == "running" }}' Trying the previous solution and it is not effective, I get an error when deactivating or activating switch: ERROR (MainThread) [homeassistant.components.rest.switch] Error while switching off http://192.168.1.15:8126/container/tasmoadmin |
Is this issue resolved or not, I am not able to run the start/stop operation by following the workaround mentioned above.
I have tried with and without |
same problem. |
Just going to re-open this while the image hasn't been completely pushed. Seems as though Travis doesn't offer Open Source for free anymore, so need to migrate the builds to GitHub actions or CircleCI. There is a new commit that should change ha-dockernon to respond to headers:
Content-Type: application/json So a full switch might look like switch:
- platform: rest
resource: http://127.0.0.1:8126/container/adguard
name: Adguard
body_on: '{"state": "start"}'
body_off: '{"state": "stop"}'
headers:
Content-Type: application/json
is_on_template: '{{ value_json is not none and value_json.state == "running" }}' This is in line with the documentation for the Rest switch on the Home Assistant website. I've manually pushed up a built image and tagged it as docker run -d \
--name=ha-dockermon --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /path/to/config:/config \
-p 8126:8126 \
philhawthorne/ha-dockermon:json |
Well, weird, it works well since 2023.6 with application/octet-stream for me. I am currently on 2023.10.5. |
Get request is working fine for me, but Post I keep getting 400 errors (UNRAID):
|
I couldn't try to install HA-Dockermon in json on my docker raspberry pi 4b, when starting I get an error: |
Hmm unfortunately with Travis no longer having a free tier (and me not updating it) I haven't got ARM builds running yet :( |
This means that there is no solution for raspberry pi 4 at the moment. |
@philhawthorne Do you have any pointers on this, is it a bug or something I'm missing? :) |
@rdlvm this should be available now, although I don't have a RPI4 to test with. I've updated the GitHub actions, which has deployed this fix to the To confirm with docker-compose, you would need something like: ha-dockermon:
image: philhawthorne/ha-dockermon:latest
container_name: ha-dockermon
restart: always
ports:
- 8126:8126
volumes:
- ./ha-dockermon:/config
- /var/run/docker.sock:/var/run/docker.sock Raspberry Pi: ha-dockermon:
image: philhawthorne/ha-dockermon:arm-latest
container_name: ha-dockermon
restart: always
ports:
- 8126:8126
volumes:
- ./ha-dockermon:/config
- /var/run/docker.sock:/var/run/docker.sock Home Assistant ConfigYour REST Switches need to be updated to: switch:
- platform: rest
resource: http://127.0.0.1:8126/container/adguard
name: Adguard
body_on: '{"state": "start"}'
body_off: '{"state": "stop"}'
headers:
Content-Type: application/json
is_on_template: '{{ value_json is not none and value_json.state == "running" }}' |
Hmm not much here I can work with. I assume these are the errors spit out from the ha-dockermon container? Can you try pulling the new |
The above was spitout by the container :P I've tried the latest tag just now, but still getting 400 bad request errors. Get is working perfectly. |
Would be great if you could update, https://philhawthorne.com/ha-dockermon-use-home-assistant-to-monitor-start-or-stop-docker-containers/, too. Would have saved me ages :) |
It seems to work now, I'll test it thoroughly and report my impressions. thanks!! |
More info on https://community.home-assistant.io/t/rest-switch-stopped-working/581188
The text was updated successfully, but these errors were encountered: