Using Input number together with command line switch

I have an A/C solution that I set the state and temperature using HTTP calls.
Currently I operate it using command line switch, with curl.
I try to use an input number as the selector of chosen temp, and bind the value in the command line switch, for instance:

input_number:
  guest_room_temp_slider:
    name: Temperature
    initial: 22
    min: 21
    max: 25
    step: 1
    unit_of_measurement: "°C"
    icon: mdi:nest-thermostat

switch:
  platform: command_line
  switches:
    guest_room_ac:
      command_on: '/usr/bin/curl -X POST https://10.0.0.8/temp/Work-room/{{ states.input_number.guest_room_temp_slider.state }}/high'
      command_off: "/usr/bin/curl -X POST https://10.0.0.8/temp/Work-room/22/off"
      command_state: "/usr/bin/curl -X GET https://10.0.0.8/temp/Work-room"
      value_template: '{{ value_json.damper == "high" }}'
      friendly_name: Guest Room A/C

Problem is, Im unable to bind the input number value in the command. Any suggestions how to deal with it?

I’m not sure if this is templateable at all - The syntax looks correct. Which error you got?

Nothing too helpful:

Command failed: /usr/bin/curl -X POST https://10.0.0.8/temp/Work-room/{{ states.input_number.guest_room_temp_slider.state }}/high
1:21 AM components/switch/command_line.py (ERROR)

Try to cast it to string:
Command failed: /usr/bin/curl -X POST https://10.0.0.8/temp/Work-room/{{ states.input_number.guest_room_temp_slider.state | string }}/high

That doesnt work either, shows the same error just with the updated attempt of | string in the log

If you have a look on the code it is just not supported so far: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/switch/command_line.py

    vol.Optional(CONF_COMMAND_OFF, default='true'): cv.string,
    vol.Optional(CONF_COMMAND_ON, default='true'): cv.string,
    vol.Optional(CONF_COMMAND_STATE): cv.string,
    vol.Optional(CONF_FRIENDLY_NAME): cv.string,
    vol.Optional(CONF_VALUE_TEMPLATE): cv.template,

I think you need to pass variables to shell command through a script. I searched the forum and found this which I think you can create a script to set temp.

Yes, I think a template switch should support that by a script.

Thanks!
Do you know a way then that I can still have my on/off switch, that will:

  1. On toggle to on/off: execute the shell command with a value taken from the input number (what you actually suggest above)
  2. will still do GET (either directly or by reading a sensor value somehow) to show the correct state of the toggle

Because the problem with shell command is that it has no state
and having a switch is important for me since Im also using it with google home

Can we also read the current value by curl from the climate by a GET?

Yes
command_state: "/usr/bin/curl -X GET https://10.0.0.8:8080/temp/Work-room"
where the value is a json which I check with value_template: '{{ value_json.damper == "high" }}'

  1. Create a shell command:
shell_command:
  guest_room_climate_set_by_slider: '/usr/bin/curl -X POST https://10.0.0.8/temp/Work-room/{{ states.input_number.guest_room_temp_slider.state | string }}/high'
  1. Create a REST sensor by (or maybe a binary REST sensor?):
sensor:
  - platform: rest
    resource: https://10.0.0.8:8080/temp/Work-room
    value_template: '{{ value_json.damper == "high" }}'
    name: guest_room_climate
  1. Create a template switch
switch:
  - platform: template
    switches:
      guest_room_climate_set_by_slider:
        value_template: "{{ is_state('sensor.guest_room_climate', 'on') }}"
        turn_on:
          service: script.guest_room_climate
        turn_off:
          service: script.??? (You need to define another shell command and another script or pass parameters to a script)
  1. Create a script:
script:
  guest_room_climate:
    sequence:
     - action:
       service: shell_command.guest_room_climate_set_by_slider

Wow, Thanks!
Its sure is a progress.
Only thing annoying is that when using a command line switch, it takes a sample of the state right after toggling it, so it immediately shows it as on or off.
When using the template, there is a delay of up to a minute until the sensor is taking a sample again.
Is there a way to force sample of the sensor? so it will be more “synced”?

Can you change the RESTsensor to:

sensor:
  - platform: rest
    resource: https://10.0.0.8:8080/temp/Work-room
    value_template: '{{ value_json.damper == "high" }}'
    name: guest_room_climate
    scan_interval: 1
1 Like