Node-red-contrib-home-assistant-websocket

yeah that’s what i was thinking.

but based on my example use case, i think it’s a good concept for a future “snapshot node” to be added to the HA palette down the road.

similar to the way you can snapshot what sonos is currently playing, have sonos play a TTS, then reload the snapshot, and it continues on.

definitely second this feature request.

I like the entity snapshot idea as well. No need for MQTT though. Store current data in NR ‘default’ memory or via persistent storage (if defined) so it survives reboot. Then an option to restore/reload.

yeah have the “snapshot node” take the list of entities, save al the states into the payload msg object. then the user can do with it as he likes. covert to json and save to mqtt, save it to global.var, whatever.

then there would need to be a second “restore node” that would take IN the payload object and restore all the states.

i would save it to mqtt cause thats where i store all my states anyways.

Here is a post that lets you save state in a traffic node:

Moved my reply here in an attempt to keep this topic cleaner and be able to follow question and answers easier over there.

Hi all

I’m trying to make a full snapshot via Nodered.
I use as example this video and it was working with node-red-contrib-home-assistant.
Now with the websocket version I’m having trouble passing the name to use to create snapshot.

This is the “format snapshot” node

msg.payload = 
{
  "data": 
  {
    "name": (new Date().toISOString().replace(':', '_').replace(':', '_').replace(/\..+/, ''))+"_Snapshot"
  }
}
return msg;

And this is the output

55

This is the call service node for snapshot

But the name of the snapshot is not the one I’ve set, but the one that automatically created.

This is the output of the snapshot call service

01

Seems to be correct.

What can I check?

Thanks

I am not a hass.io user but I tested your setup on my test hass.io server and it seemed to created the snapshot with the correct name just fine.

[{"id":"3aedc0f6.6417a","type":"api-call-service","z":"5eb3594f.d294b8","name":"","server":"ef067c6f.620e6","service_domain":"hassio","service":"snapshot_full","data":"","mergecontext":"","output_location":"payload","output_location_type":"msg","x":462,"y":656,"wires":[["b74fe511.585188"]]},{"id":"3da426b1.6c6bda","type":"inject","z":"5eb3594f.d294b8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":108,"y":656,"wires":[["2229a92f.126cd6"]]},{"id":"b74fe511.585188","type":"debug","z":"5eb3594f.d294b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":678,"y":656,"wires":[]},{"id":"2229a92f.126cd6","type":"function","z":"5eb3594f.d294b8","name":"","func":"msg.payload = {\n  \"data\": {\n    \"name\": (new Date().toISOString().replace(':', '_').replace(':', '_').replace(/\\..+/, ''))+\"_Snapshot\"\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":258,"y":656,"wires":[["3aedc0f6.6417a"]]}]

Thanks @Kermit

This is exactly what I’m doing.
I’ve tried your flow and msg.payload is correct

17

but then the file is saved as

36

just like mine.

Really strange!

PS:
I’ve got it, it’s not the file name that is going to be changed, but the text when I look at the Snapshots list!

56

Sorry, I thought was the fine name was going to change… :flushed:

New Release v0.8.0

Bug Fixes

Features

  • wait-until: Added ability to check against current state (c6343a9)
  • Able to access flow global and states in templates (e0de7cb)
  • hass.io connection delay toggleable (11c440c)

Full Changelog


Templates for the call-service and fire-event nodes

You can use templates in the Entity Id and data fields. When using templates the top level is a property of the message object: msg.payload would be {{payload}} . You can also access the flow, global and states contexts {{flow.foobar}} {{global.something}} . For the states context you can use the {{states.domain.id}} to just get the state or drill further down like {{states.light.kitchen.attributes.friendly_name}} . {{states.light.kitchen}} and {{states.light.kitchen.state}} are equivalent.


Buy me a coffee For those that enjoy my work.

2 Likes

It should be {{states.entity_id}} right? otherwise it would be like {{states.light.light.kitchen}}

Thanks again for keeping this node updated :+1:

I guess you are correct {{states.entity_id}} would be more inline with how things are called within the nodes. I was thinking more of the id of the entity from home assistant. Would probably have been better to do {{states.domain.id}} as the entity_id is already the concatenated version of the domain and id.

Hi @Kermit, I just upgraded to 0.8.0 from 0.6.0 last night, and it looks like all my flows that use the current state node have stopped working. When I edit the node, the ‘Halt if State’ text box is not visible. Any idea if this is upgrade related? Or something else going on?

image

I believed I moved the halt if logic to an imported external file somewhere between 0.6 and 0.8. So it might be that it didn’t load properly for you. Can you check your browser console and see if you have any errors in it after opening a current-state node? Also, did you restart node-red and refresh the browser page after upgrading? Does it show correctly for a poll-state node?

Environment (please complete the following information):

  • Node Red Version: [e.g. 0.19.5]
  • NR Home Assistant Plugin Version: [e.g. 0.5.0]
  • Is Node Red running in Docker: [e.g. yes/no/hassio]
  • Browser:

I’m not seeing any errors in the browser console (only 2 entries actually). The poll state node also has the same issue. I restarted node-red a few times, and have tried a couple different computers/browsers.

Here is my environment information:

  • Node Red Version: 0.18.7
  • NR Home Assistant Plugin Version: 0.8.0
  • Is Node Red running in Docker: yes (HA 0.87.1
  • Browser: Safari and Chrome

Thanks again for any help.

Try upgrading node-red to a version 0.19+

That was it. I didn’t realize I haven’t updated that container for a long time. Upgraded to 0.19.6, and it is working again.

Thanks again!

Any idea what the following error would be from? Everything seems to be working okay and I can connect to the server just fine. Note, that this is on a rpi zero w that’s not running HA.

Node-Red Version: 0.19.6
Run in Docker: No

Screenshot%20from%202019-03-02%2021-25-55

For some reason, lodash didn’t get installed by npm when the module got installed. You could uninstall and try reinstalling or run npm install lodash from within the node-red directory.

Super easy fix! I did npm install and the error is no longer there.

I’ve been tracking this thread for a few months now and it amazes me at how you continue to both develop the module and support people who have questions with it. Keep up the great work!