Node-red-contrib-home-assistant-websocket

New Release v0.14.0

Features

  • JSONata everywhere (6424235)
  • api: Add option for data field to be a JSONata Expr (37b54ce)
  • call-service: Add JSONata option to data field (8e91f42)
  • fire-event: Add option for data field to be a JSONata Expr (526d083)
  • get-entities: Allow overriding of config values from payload (a0fdb96), closes #133

JSONata

  • There are three functions added for JSONata expressions within the Home Assistant nodes
    • $entity() returns the entity that triggered the node
    • $prevEntity() returns the previous state entity if the node is an event node
    • $entities() returns all entities in the cache
    • $entities(entity_id) returns a single entity from cache matching passed in entity_id

When JSONata appears in the conditional dropdown it expects the expression to return a boolean, true or false.

image

When it is chosen with a conditional, not JSONata it will return a value of the evaluated expression that will be checked against the conditional chosen.

image

Call-Service Node Changes

  • Entity ids are no longer merged with the data property on the front end
  • The data field does not have to be valid JSON until after templates are rendered. This change will allow you to assign numbers to properties as an actual number and not a string using templates.
  • entity_id in the data property will supersede the entity id field
  • Flows exported from version 0.14.0 will lose the entity id when imported into a previous version

Notice: Just because the text is yellow on a node doesnā€™t mean you need to go update it. It will continue to function just as it is and the next time you modify the node it will be upgraded then.

Full Changelog


Buy me a coffee For those that enjoy my work.

5 Likes

Thanks for the update, Iā€™ve just updates, redeployed nodes, etc. and all working great so far. :slight_smile:

Hello @Kermit,

Iā€™m running docker on a raspberry pi.

Here is my log:

Thanks again for your help on this. I really appreciate it!

I know it runs right out of the box on rpi using docker. Maybe try rebuilding the container also not sure if youā€™re already using it or not but I recommend using the raymondmm/node-red image.

Hello again Kermit and thanks

I have rebuilt the container a few times using the image you have prescribed in other posts and above. Here is the log:

> [email protected] start /usr/src/node-red,
> node $NODE_OPTIONS node_modules/node-red/red.js -v $FLOWS "--userDir" "/data",
,
25 Jul 03:15:19 - [info] ,
,
Welcome to Node-RED,
===================,
,
25 Jul 03:15:19 - [info] Node-RED version: v0.20.5,
25 Jul 03:15:19 - [info] Node.js  version: v10.15.3,
25 Jul 03:15:19 - [info] Linux 4.19.42-v7+ arm LE,
25 Jul 03:15:20 - [info] Loading palette nodes,
Thu, 25 Jul 2019 03:15:23 GMT node-telegram-bot-api deprecated Automatic enabling of cancellation of promises is deprecated.,
In the future, you will have to enable it yourself.,
See https://github.com/yagop/node-telegram-bot-api/issues/319. at internal/modules/cjs/loader.js:701:30,
25 Jul 03:15:24 - [warn] rpi-gpio : Cannot find Pi RPi.GPIO python library,
25 Jul 03:15:24 - [warn] Missing node modules:,
25 Jul 03:15:24 - [warn]  - node-red-contrib-home-assistant-websocket (0.14.0): server, server-events, server-state-changed, trigger-state, poll-state, api-call-service, ha-fire-event, api-current-state, ha-get-entities, api-get-history, api-render-template, ha-wait-until, ha-api,
25 Jul 03:15:24 - [info] Removing modules from config,
25 Jul 03:15:25 - [info] Settings file  : /data/settings.js,
25 Jul 03:15:25 - [info] Context store  : 'default' [module=memory],
25 Jul 03:15:25 - [info] User directory : /data,
25 Jul 03:15:25 - [warn] Projects disabled : editorTheme.projects.enabled=false,
25 Jul 03:15:25 - [info] Flows file     : /data/flows.json,
25 Jul 03:15:25 - [info] Server now running at http://127.0.0.1:1880/,
25 Jul 03:15:25 - [warn] ,
,
---------------------------------------------------------------------,
Your flow credentials file is encrypted using a system-generated key.,
,
If the system-generated key is lost for any reason, your credentials,
file will not be recoverable, you will have to delete it and re-enter,
your credentials.,
,
You should set your own key using the 'credentialSecret' option in,
your settings file. Node-RED will then re-encrypt your credentials,
file using your chosen key the next time you deploy a change.,
---------------------------------------------------------------------,
,
25 Jul 03:15:25 - [info] Waiting for missing types to be registered:,
25 Jul 03:15:25 - [info]  - server,
25 Jul 03:15:25 - [info]  - trigger-state,
25 Jul 03:15:25 - [info]  - api-current-state,
25 Jul 03:15:25 - [info]  - api-call-service,
25 Jul 03:15:25 - [info]  - server-state-changed,
25 Jul 03:15:25 - [info]  - ha-get-entities,
25 Jul 03:15:25 - [info]  - server-events,
25 Jul 10:53:53 - [info]  Disabled node types:,
25 Jul 10:53:53 - [info]  - twitter-credentials,
25 Jul 10:53:53 - [info]  - twitter in,
25 Jul 10:53:53 - [info]  - twitter out,
25 Jul 11:31:44 - [info] Installing module: node-red-contrib-home-assistant-websocket, version: 0.14.0,
25 Jul 11:32:52 - [info] Installed module: node-red-contrib-home-assistant-websocket,
25 Jul 11:32:53 - [info] Missing type registered: server-events,
25 Jul 11:32:53 - [info] Missing type registered: server-state-changed,
25 Jul 11:32:53 - [info] Missing type registered: api-call-service,
25 Jul 11:32:53 - [info] Missing type registered: api-current-state,
25 Jul 11:32:53 - [info] Missing type registered: ha-get-entities,
25 Jul 11:32:53 - [info] Missing type registered: trigger-state,
25 Jul 11:32:53 - [info] Added node types:,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:server : Error: Cannot find module 'debug' (line:6),
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:server-events,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:server-state-changed,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:trigger-state,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:poll-state,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:api-call-service,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:ha-fire-event,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:api-current-state,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:ha-get-entities,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:api-get-history,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:api-render-template,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:ha-wait-until,
25 Jul 11:32:53 - [info]  - node-red-contrib-home-assistant-websocket:ha-api,

I notice the credential error, but from what I have read that that is an independant issue with creating a token and modifying the /opt/node-red/settings.js file.

I greatly appreciate your assistance.

Can the jsonata functions be called from within any nodered jsonata expression? Or only the ha nodes ?

Only in HA nodes

1 Like

Can anyone post an example using jasonata?

To whom it may concern- I was able to fix my issue by stopping the container, exporting all my flows, deleting everything in the data folder, rebuilding the container, then finally importing all of the flows. Thanks again @Kermit for your assistance and development of this awesome addon.

What kind of examples are you looking for?

How about an example of using it to populate the data of a call service node?

What I am asking is a use case example. I am not sure where or when this would be useful.

Have you used jsonata before?
I havenā€™t used yet the jsonata in ha nodes but I do use them quite a lot in switch and change node.
I have a flow, executes at certain time is for turning the heater in the morning. I need to first check temp, if is under a value but I wanted that temp limit to be adjustable so use an input_number. So it will only pass if temp is below that input number. Now I can do that with jsonata and the included ha function. ATM what I have is a state change node that stores the input number value in context.

@silfa718 @MizterB I broke it out into a seperate post.

@Kermit I was wondering if you had any examples of the API node? Iā€™m trying to query /zha/devices via websockets as in the below lovelace card but Iā€™m not having any success so far.

1 Like

Hi,

I just canā€™t wrap around my head about this error after a change in entity-idā€™s in the latest version.
Iā€™m calling ā€œvolume upā€/ā€œVolume downā€ and so ne with a entity id stored in a flow. variable (called flow.lautsprecher_id)
I always just used {{flow.lautsprecher_id}} as value for entity id. This results in an API-error after changing the node.

I tried:

{
    "entity-id": "{{flow.lautsprecher_id}}"
}

in the data field, but still: API error.
What am I doing wrong?

Itā€™s an underscore in the entity_id. You are able to enter {{flow.lautsprecher_id}} directly into the entity id field.

1 Like

yeah, itā€™s indeed an underscore. Strange is, that {{flow.lautsprecher_id}} did not work for the last couple of days.
Now itā€™s working (after reverting the changes)
Still, thank you!

Iā€™m trying to use a template with | lower() and NR doesnā€™t seem to like passing it over to TG (thereā€™s just an empty space). The below code works but the state is uppercase (which isnā€™t the end of the world but iā€™d prefer it lowercase). Any suggestions?

{ "title": "*Good morning!*", "message": "It is currently {{ states.sensor.dark_sky_temperature.state }} degrees and {{ states.sensor.dark_sky_summary.state }} outside. It feels like {{ states.sensor.dark_sky_apparent_temperature.state }} degrees with {{ states.sensor.dark_sky_humidity.state }}% humidity. The nearest storm is {{ states.sensor.dark_sky_nearest_storm_distance.state }} miles away to the {% if states('sensor.dark_sky_nearest_storm_bearing') | float >= 315 or states('sensor.dark_sky_nearest_storm_bearing') | float < 45 %}north. {% elif states('sensor.dark_sky_nearest_storm_bearing') | float >= 45 or states('sensor.dark_sky_nearest_storm_bearing') | float < 135 %}east. {% elif states('sensor.dark_sky_nearest_storm_bearing') | float >= 135 or states('sensor.dark_sky_nearest_storm_bearing') | float < 225 %}south. {% elif states('sensor.dark_sky_nearest_storm_bearing') | float >= 225 or states('sensor.dark_sky_nearest_storm_bearing') | float < 315 %}west. {%endif %}" }