node-red-contrib-home-assistant icon indicating copy to clipboard operation
node-red-contrib-home-assistant copied to clipboard

Problem calling "Call Service" twice in linked nodes

Open michaelblight opened this issue 7 years ago • 3 comments

I'm not sure if this is a bug or not as I'm still pretty new here. If I have two 'Call Service' nodes linked together, only the first runs. In my case I'm trying to change an input_number from -1 to 1 via 0 (ie. set_value to 0 then set_value to 1). This is because I need a tri-state boolean and I go via 0 to ensure events fire even if going from 1 to 1.

I'm currently making it work by using a script that does the two steps, and then calling the script from Node Red. So the script to go 'to 1' is:

  - service: input_number.set_value
    data:
      value: 0
      entity_id: input_number.heater_state
  - service: input_number.set_value
    data:
      value: 1
      entity_id: input_number.heater_state

michaelblight avatar Jun 09 '18 14:06 michaelblight

I'm seeing something slightly different. When I have 2 service nodes linked, neither actually calls home assistant. Very strange.

blackgold9 avatar Jul 03 '18 07:07 blackgold9

I think it's even more strange than that. I set up an input_number and had three separate sequences.

The first did a get (current_state) followed by a debug. As expected, I got 0.0.

The second did 3 service calls - two to increment and one to get, prior to a debug. Running this the output should have been 2.0, but it was 0.0 - implying only the get worked.

The third sequence did 2 service calls - one to increment and one to get, prior to a debug. When I then ran that, given that I was starting with 0.0, I would expect 1.0, but I got 2.0.

Then I ran the first again and got 4.0, despite the fact it shouldn't have changed the value.

BUT EUREKA! I think this shows what's going on. I'm guessing they're all executing, but asynchronously for some/all.

michaelblight avatar Jul 03 '18 08:07 michaelblight

Supporting my comments above, inserting a delay of 1s between each HA call made everything work. I tried 1ms, but no luck, so I guess that's too fast. In my case, a couple of 1s delays is fine.

michaelblight avatar Jul 03 '18 08:07 michaelblight