AYapejian / node-red-contrib-home-assistant

Home Assistant + Node-Red
MIT License
75 stars 33 forks source link

Call Service Node: Allow batching service calls by incoming payload data #24

Open AYapejian opened 6 years ago

AYapejian commented 6 years ago

Batch service calls, something like below (needs fleshing out)

msg = {
    payload: {
        options: { throttle: { requestsPerSecond: 2 } },
        batch: [
            { domain: 'light',      service: 'turn_on',         data: { entity_id: 'light.light1' }   },
            { domain: 'switch',     service: 'turn_on',         data: { entity_id: 'switch.switch1' } },
            { domain: 'thermostat', service: 'set_temperature', data: { entity_id: 'thermostat.upstairs', termperature: 22 } }
        ]
    }
};
mcfarlde commented 6 years ago

This will be great!

mcfarlde commented 6 years ago

What syntax works to include an effect? { "entity_id":"light.hannahs_bedside" , "effect":"colorloop" } in a call service node doesn't.

AYapejian commented 6 years ago

To send data to a service set the data property of the incoming payload:

msg.payload = { "data": { "entity_id": "light.entity123", "effect": "colorloop" } }

FYI: Node help tab should say as much

If the incoming message has a payload property with domain, service or data set it will override any defaults(if any) set within the node configuration.

mcfarlde commented 6 years ago

I'm not using the incoming message, I'm setting it in the data field of the api_service_call node. Looks like I may be missing some spaces. Thanks.

oakbrad commented 6 years ago

Seems like this has kind of been done with the new 'batch' node to make message sequences?

https://nodered.org/blog/2018/01/31/version-0-18-released