#websocket (input_number/set_value) service doesnt seem to function

17 messages · Page 1 of 1 (latest)

rigid prairie
#

I found some odd behaviour in the websockets and i cant find any documentation about it. Trying to set a number value via websockets at the moment, i have success doing other service calls like sending my vacuum cleaner somewhere (via websockets)

So posting /api/states/number.entity_id with {state: 42.5} works fine, but calling the service's from the websocket:

 {
    "type": "call_service",
    "domain": "input_number",
    "service": "set_value",
    "service_data": {
        "value": 42.5
    },
    "target": {
        "entity_id": "input_number.your_entity_id"
    }
}

fail to do anything, while i do get a context block back, i dont get any actual state difference's

I tried to look at the websocket lib of home assistant and i cant find anything using the set_value, so i guess its not used? But when i get all the services, it says it is supported

{
  // (...)
  "input_number": {
    "set_value" : {
      "name" : "Set",
      "description" : "Sets the value.",
      "fields" : {
        "value" : {
          "required" : true,
          "selector" : {
            "number" : {
              "min" : 0,
              "max" : 9223372036854776000,
              "step" : 0.001,
              "mode" : "box"
            }
          },
          "name" : "Value",
          "description" : "The target value."
        }
      },
      "target" : {
        "entity" : [ {
          "domain" : [ "input_number" ]
        } ]
      }
    }
  }
  // (...)
}

So that indicates it should work like this. My work around right now is to just use the API, but i prefer to use the websockets 🙂

rigid prairie
#

Bump

rigid prairie
#

Bump

vapid socket
#

How are you calling from the websocket exactly? Are you using home-assistant-js-websocket library?

#

input_number.set_value is how frontend updates the value when the ui fields are changed, so it is used...

rigid prairie
#

No libary, just nodejs with websockets

#

So the json blob above i send with the nodejs

#

But please, again, i have not a problem in general with using websockets, it is working fine, just this specific call to set a number seems to not funciton (while i get data back when calling correctly), it simply doesnt set the data

rigid prairie
#

I also get validation errors when i on purpose send the wrong data, so im pretty sure i call the right endpoint

vapid socket
#

Well if you put an input number in an entities card, it use the hui-input-number-entity-row, and value changed calls the callService method on home-assistant-js-websocket.

#

Sorry I'm not sure why your method doesn't work, as best I can tell the object looks reasonable.

regal delta
#

I'm also not sure why your example is not working, but it looks like the frontend is setting the entity_id in the service data instead, not using target

{
  "type": "call_service",
  "domain": "input_number",
  "service": "set_value",
  "return_response": false,
  "service_data": {
    "value": 1,
    "entity_id": "input_number.foo"
  },
  "id": 53
}
vapid socket
#

AFAIK both approaches are valid

#

I tried using target and that was fine (via hass.callService)

rigid prairie