#FIXED: Command line curl with value of a slider and state as condition

1 messages · Page 1 of 1 (latest)

meager tree
#

Hi, I am trying to setup this an optional shutdown delay when turning of the computer. so I would be able to delay it about 60 minutes or 120 depending on the value. I am using a tool installed on the pc that functions through http.

The command is:
`command_line:

  • switch:
    name: pc_off
    command_off: "curl http://IPADDRESS:PORT/secret_key/forceshutdown?delay={{ states('input_number.shutdown_delay') | int * 60 }}"`

But my HASS log reports me:
2024-03-21 21:21:40.952 ERROR (SyncWorker_36) [homeassistant.components.command_line.utils] Command failed (with return code 2): curl http://IPADDRESS:PORT/secret_key/forceshutdown?delay={{ states('input_number.shutdown_delay') | int * 60 }} 2024-03-21 21:21:40.952 ERROR (MainThread) [homeassistant.components.command_line] Command failed: curl http://IPADDRESS:PORT/secret_key/forceshutdown?delay={{ states('input_number.shutdown_delay') | int * 60 }}

#

This above config does not even include the state of the switch I also wanted to add, something like:
{{ if 'Yes' states('input_boolean.shutdown_delay') }}

dense vigil
#

according to docs command_off takes a string, not a template. so that may not be templatable

meager tree
#

Hmm, but "command" does take templates according to the docs, right?

dense vigil
#

it says "string"

#

oh hmm nevermind an example does use templates 🤔

meager tree
#

yeah, let me try

dense vigil
#

you can make a service with custom inputs, and then you call that service with your custom delay

meager tree
#

I read that, but from the documentation I don't know where to start. It is just a simple http link. REST asks for content type and jsons.. 😛

dense vigil
#

I think that's all optional

meager tree
#

So configuration.yaml:

rest_command: example_request: url: > http://IPADDRESS:PORT/secret_key/forceshutdown?delay={{ states('input_number.shutdown_delay') | int * 60 }}

dense vigil
#

Do you need a newline after a block string indicator?

#
rest_command:
  example_request:
    url: >
      http://IPADDRESS:PORT/secret_key/forceshutdown?delay={{ states('input_number.shutdown_delay') | int * 60 }}

maybe like this

meager tree
#

I added it now wihtout >
Should it show up as entity? it did not throw any errors at least.

dense vigil
#

not an entity but a service

#

rest_command.example_request I think

meager tree
#

I see, let me test the by calling the service then.

#

no service is shown with that name unfortunately.

dense vigil
#

restarted HA?

meager tree
#

no, i reloaded config.yaml. ill reboot for it to detect the integration 🙂 thanks for the reminder.

#

wow, it actually shows the value now. but there was an error:
Client error occurred when calling resource 'curl http://IP:port/secret/forceshutdown?delay=6540'

#

Ah fixed it now!

shell_command: shell_shutdown_dax_pc: "curl http://IPADDRESS:PORT/secret_key/forceshutdown?delay={{ states('input_number.shutdown_delay') | int * 60 }}

#

FIXED: Command line curl with value of a slider and state as condition