Skip to content

Commit

Permalink
feat(action)!: Add selector for floor and label
Browse files Browse the repository at this point in the history
refactor(action)!: Rename call-service node to action

Home Assistant is rebranding service calls to actions.

BREAKING CHANGE: The call-service node has been renamed to the action node. The domain and service input properties are deprecated and will be removed in version 1.0. Please use the action property instead.
  • Loading branch information
zachowj committed Aug 4, 2024
1 parent 36c2c9d commit 20e08ab
Show file tree
Hide file tree
Showing 33 changed files with 1,099 additions and 648 deletions.
31 changes: 24 additions & 7 deletions docs/.vuepress/client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { defineClientConfig } from '@vuepress/client';

const redirectRoutes = [
{
from: '/cookbook/get-entities.html',
to: '/node/get-entities.html',
},
{
from: '/guide/custom_integration/switch.html',
to: '/node/switch.html',
},
{
from: '/node/call-service.html',
to: '/node/action.html',
},
{
from: '/guide/call-service.html',
to: '/guide/action.html',
},
];

export default defineClientConfig({
enhance({ router }) {
router.addRoute({
path: '/cookbook/get-entities.html',
redirect: '/node/get-entities.html',
});
router.addRoute({
path: '/guide/custom_integration/switch.html',
redirect: '/node/switch.html',
redirectRoutes.forEach((route) => {
router.addRoute({
path: route.from,
redirect: route.to,
});
});
},
});
4 changes: 2 additions & 2 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default defineUserConfig({
children: [
'/guide/',
'/guide/first-automation',
'/guide/call-service',
'/guide/action',
'/guide/conditionals',
'/guide/mustache-templates',
{
Expand Down Expand Up @@ -136,8 +136,8 @@ export default defineUserConfig({
text: 'General Nodes',
collapsible: true,
children: [
'action',
'API',
'call-service',
'current-state',
'device',
'events-all',
Expand Down
18 changes: 9 additions & 9 deletions docs/guide/call-service.md → docs/guide/action.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Call Service Tips and Tricks
# Action Tips and Tricks

## Homeassistant Domain

The `homeassisant` domain can be used with different domains of entities with certain services.

Here's an example of using the `homeassistant` domain to turn off some lights, switches, and everything that can be turned off in the laundry room in a single service call. This can save you from having to have multiple call-service nodes.
Here's an example of using the `homeassistant` domain to turn off some lights, switches, and everything that can be turned off in the laundry room in a single service call. This can save you from having to have multiple action nodes.

![screenshot of a call-service node using homeassistant domain](./images/call-service_06.png)
![screenshot of a action node using homeassistant domain](./images/call-service_06.png)

## Using Mustache Templates

Mustache templates can be used in the domain, service, and entity id fields. This is useful if you want to set the service based on `msg.payload` or any other message property.

Here's an example using [eztimer](https://flows.nodered.org/node/node-red-contrib-eztimer) to set the output of the node to `on` or `off`. Then use that in the call-service node for which service to use.
Here's an example using [eztimer](https://flows.nodered.org/node/node-red-contrib-eztimer) to set the output of the node to `on` or `off`. Then use that in the action node for which service to use.

![screenshot of flow](./images/call-service_01.png)

![screenshot of the call-service node](./images/call-service_03.png)
![screenshot of the action node](./images/call-service_03.png)

@[code](@examples/guides/call-service/mustache_templates_01.json)

Expand Down Expand Up @@ -49,7 +49,7 @@ It's recommended to use the JSONata expression, `J: Expression`, for the data fi

![screenshot of flow](./images/call-service_04.png)

![screenshot of the call-service node](./images/call-service_05.png)
![screenshot of the action node](./images/call-service_05.png)

```json
{ "message": "The " & data.attributes.friendly_name & " has been opened." }
Expand Down Expand Up @@ -87,7 +87,7 @@ Home Assistant states are represented as strings so to be able to do arithmetic

#### Adding 3 to the current temperature of a climate entity

![screenshot of call-service node](./images/call-service_02.png)
![screenshot of action node](./images/call-service_02.png)

```json
{ "temperature": $entities("climate.thermostat").attributes.temperature + 3 }
Expand All @@ -99,7 +99,7 @@ Example of getting a list of lights from the get-entities node and then creating

![screenshot of flow](./images/call-service_07.png)

![screenshot of call-service node](./images/call-service_08.png)
![screenshot of action node](./images/call-service_08.png)

```json
{ "entity_id": $join(payload.entity_id, ",") }
Expand All @@ -109,7 +109,7 @@ Example of getting a list of lights from the get-entities node and then creating

**Also see:**

- [Call-service node](../node/call-service.md)
- [Action node](../node/action.md)
- [JSONata Guide](./jsonata.md)
- [https://docs.jsonata.org](https://docs.jsonata.org)
- [http://try.jsonata.org](http://try.jsonata.org)
8 changes: 4 additions & 4 deletions docs/node/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Nodes

## [Action](./action.md)

Sends a request to Home Assistant to perform an action e.g. `light.turn_on`, `input_select.select_option`, etc.

## [API](./API.md)

Access all points of the WebSocket and HTTP API.
Expand All @@ -12,10 +16,6 @@ Creates a binary sensor entity in Home Assistant that is controlled from with No

Creates a button in Home Assistant that triggers a flow in Node-RED

## [Call Service](./call-service.md)

Sends a request to home assistant for any domain and service available ( `light/turn_on`, `input_select/select_option`, etc..)

## [Current State](./current-state.md)

Fetches the last known state for any entity on input
Expand Down
65 changes: 31 additions & 34 deletions docs/node/call-service.md → docs/node/action.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
# Call Service
# Action

Sends a request to home assistant for any domain and service available (`light/turn_on`, `input_select/select_option`, etc..)
Sends a request to Home Assistant to perform an action e.g. `light.turn_on`, `input_select.select_option`, etc.

::: tip Helpful Examples
[Call Service Tips and Tricks](/guide/call-service.html)
[Action Tips and Tricks](/guide/action.html)
:::

## Configuration

### Domain <Badge text="required"/>
### Action <Badge text="required"/>

- Type: `string`
- Accepts [Mustache Templates](/guide/mustache-templates.md)

Service domain to call
Action to perform

A custom domain can be used by adding a `#` at the end of the domain
### Floor

### Service <Badge text="required"/>

- Type: `string`
- Accepts [Mustache Templates](/guide/mustache-templates.md)

Service to call
- Type: `an array of floor ids`
- Accepts [Mustache Templates](/guide/mustache-templates.md) for ids

Custom service can be used by adding a `#` at the end of the service
A list of floor ids that will be used as targets for the action

### Area

- Type: `an array of area ids`
- Accepts [Mustache Templates](/guide/mustache-templates.md) for ids

A list of area ids that will be used as targets for the service call
A list of area ids that will be used as targets for the action

Custom ids can be inserted into the list by adding a `#` at the end of the id

Expand All @@ -40,7 +36,7 @@ Custom ids can be inserted into the list by adding a `#` at the end of the id
- Type: `an array of device ids`
- Accepts [Mustache Templates](/guide/mustache-templates.md) for ids

A list of device ids that will be used as targets for the service call
A list of device ids that will be used as targets for the action

Custom ids can be inserted into the list by adding a `#` at the end of the id

Expand All @@ -49,7 +45,14 @@ Custom ids can be inserted into the list by adding a `#` at the end of the id
- Type: `an array of entity ids`
- Accepts [Mustache Templates](/guide/mustache-templates.md) for ids

A list of entity ids that will be used as targets for the service call
A list of entity ids that will be used as targets for the action

### Label

- Type: `an array of label ids`
- Accepts [Mustache Templates](/guide/mustache-templates.md) for ids

A list of label ids that will be used as targets for the action

### Data

Expand Down Expand Up @@ -84,12 +87,13 @@ Sample input

```JSON
{
"domain": "homeassistant",
"service": "turn_on",
"action": "homeassistant.turn_on",
"target": {
"floor_id": ["first_floor"],
"area_id": ["kitchen"],
"device_id": ["8932894082930482903"],
"entity_id": ["light.kitchen", "switch.garage_light"]
"entity_id": ["light.kitchen", "switch.garage_light"],
"label_id": ["outdoor_lights"]
}
"data": {
"brightness_pct": 50
Expand All @@ -99,7 +103,7 @@ Sample input

#### Merging

If the incoming message has a `payload` property with `domain`, `service` set it will override any config values if set.
If the incoming message has a `payload` property with `action` set it will override any config values if set.

If the incoming message has a `payload.data` that is an object these properties will be <strong>merged</strong> with any config values set.

Expand All @@ -109,32 +113,25 @@ If the node has a property value in its config for `Merge Context` then the `flo

As seen above the `data` property has a lot going on in the way of data merging, in the end, all of these are optional and the rightmost will win if a property exists in multiple objects

Config Data, Global Data, Flow Data, Payload Data ( payload data property always
wins if provided

### domain

- Type: `string`

Service domain to call
Config Data, Global Data, Flow Data, Payload Data ( payload data property always wins if provided )

### service
### action

- Type: `string`

Service service to call
Action to call

### data

- Type: `JSON Object`

Service data to send with the service call
Data to send with the action

### target

- Type: `JSON Object with area_id, device_id, and entity_id as array properties`
- Type: `JSON Object with floor_id, area_id, device_id, entity_id, and label_id as array properties`

Targets of the service call
Targets of the action

## Output

Expand All @@ -148,6 +145,6 @@ Value types:

<info-panel-only>

[External Docs](/node/call-service.md)
[External Docs](/node/action.md)

</info-panel-only>
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ const resourcePath = 'resources/node-red-contrib-home-assistant-websocket';
const resourceFiles = [
`<script src="${resourcePath}/select2.full.min.js?v=4.1.0-rc.0"></script>`,
`<link rel="stylesheet" href="${resourcePath}/select2.min.css?v=4.1.0-rc.0">`,
`<link rel="stylesheet" href="${resourcePath}/virtual-select.v1.0.44.min.css">`,
`<script src="${resourcePath}/virtual-select.v1.0.44.min.js"></script>`,
`<script src="${resourcePath}/maximize-select2-height.min.js?v=1.0.4"></script>`,
`<script src="${resourcePath}/handlebars.min-v4.7.8.js"></script>`,
];

const nodeMap = {
action: { doc: 'action', type: 'api-call-service' },
api: { doc: 'API', type: 'ha-api' },
'binary-sensor': { doc: 'binary-sensor', type: 'ha-binary-sensor' },
button: { doc: 'button', type: 'ha-button' },
'call-service': { doc: 'call-service', type: 'api-call-service' },
'config-server': { doc: 'config-server', type: 'server' },
'current-state': { doc: 'current-state', type: 'api-current-state' },
device: { doc: 'device', type: 'ha-device' },
Expand Down
Loading

0 comments on commit 20e08ab

Please sign in to comment.