Using just one Call-Service-Node to change setting - can it be done

Is it possible to change values of a input_boolean variable with just one Call-Service Node (Api-Call-Service).

A turn_on and turn_off call service node is normally used (two nodes) but when the number of input_boolean nodes are large, it would be “nice” if just one could do the task.

Any suggestions on how to do this ?

There’s a few ways, but the easiest would be either using a Function node in front of the call-service node or mustache templating in the call-service node.

For a Function node, you could do something like this:

var state = msg.payload;
msg.payload = {
    domain: 'input_boolean',
    service: 'turn_' + state,
    entity_id: 'input_boolean.something'
}

return msg;

For mustache templating, in your service, you could set it to turn_{{payload}}.

I prefer function nodes myself:


var mode    = global.get("mode", "file");

node.status({fill:"green", shape: "ring", text: mode });

mode = mode.toLowerCase().replace(" ", "_");

msg.payload = {
    domain: "scene",
    service: "turn_on",
    data: {
        entity_id: "scene.kitchen_" + mode
    }
};

return msg;

image

1 Like

Works perfectly code-in-progress. Thanks !

1 Like