Node-red-contrib-home-assistant-websocket

I was going off of memory and was incorrect. The get history is special I guess it wants its inputs on the msg level, not in msg.payload so msg.entity is what you want to set.

The information is definitely in the information tab all nodes show what they accept as input there.

image

@Kermit - Yes I meant that it doesnt mention how to set the entityid via payload there.

This worked:

msg = {
entityid: sensor.XXX
};
return msg;

thanks!!

Hi,

I’ve tried to solve this myself and have come to “end of my tether” point. Not helped that I started to try using hass-post before finding that it doesn’t work with the new HA authentication. Then came across the the suggestion to use “ha-fire-event” to change a state.

I’m trying to change an input_number in HA. I’m totally failing on this, even just trying to use the ha-fire-event node with an inject trigger.

[{"id":"e5e08bd7.33dcb8","type":"ha-fire-event","z":"9ea69359.2fdaf","name":"Change State","server":"3747e79a.f1fc38","event":"input_number.alarm_clock_hour","data":"{\"input_number.alarm_clock_hour.state\":\"05\"}","dataType":"json","x":640,"y":520,"wires":[["c2f199a5.5c3ee8","1aeb1ac9.f07b85"]]},{"id":"3747e79a.f1fc38","type":"server","z":"","name":"Pinky","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Any help greatly appreciated.

1 Like

image

[{"id":"9360df3b.2d5e8","type":"inject","z":"9ce184b.0f5bb78","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":608,"wires":[["c7ddd768.b0d8d8"]]},{"id":"c7ddd768.b0d8d8","type":"api-call-service","z":"9ce184b.0f5bb78","name":"","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.alarm_clock_hour","data":"{\"value\": 5}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":376,"y":608,"wires":[[]]}]
1 Like

You are a superstar. Many thanks.

New Release 0.17.0

This release brings two new nodes and an additional feature to existing event nodes. These new nodes will require a custom integration to be installed as companion to node-red-contrib-home-assistant-websocket.

If you choose not to install the custom integration this package will continue to function as it always has you just won’t be able to use the new sensor and webhook nodes or have the ability to expose event nodes to Home Assistant.

Sensor Node: image

It will create a sensor or binary sensor inside Home Assistant that can be updated directly from Node-RED.

Webhook Node: image

Creates a webhook in Home Assistant that will be handled by Node-RED.

https://[ip]:[port]/api/webhook/LvNwB2ckjGWyYGVvArJ0uCUbQFrqAWcg

Event Nodes (events: all, events: state, trigger: state, and poll state):

Will have the option to be exposed to Home Assistant, and when enabled, it will show up in Home Assistant as a switch. Turning on and off these switches will disable/enable the nodes in Node-RED. This should help people who find themselves having to make input_booleans in HA to enable/disable flows.
image

Installation

Installation of custom integration can be done using HACS or manually, instruction can be found in the README.

Tip:

Filling in the name field in the HA config of these new nodes before you first deploy will attempt to create it with that entity_id otherwise it will default to sensor.nodered_79fba2c4_04342c. Where the random string is the node id in Node-RED. The entity ids change be changed in HA after creating them in NR.

image


Bug Fixes

  • call-service: Remove spaces around entity ids for homeassistant domain (564670a), closes #170

Features


Buy me a coffee For those that enjoy my work.

13 Likes

This is a great feature to allow for custom sensors, thanks.

Up until now I’ve been updating ‘input text’ values and while it kind of works this way looks much nicer.

EDIT: Is it required to restart HA every time I create or remove a sensor in NodeRED?

Not at all.

1 Like

Great stuff, thanks. With some other components I have to keep restarting HA with every change, but it’s so nice not to have to do that.

I’ve only added 3 sensors so far, and so far it’s working great, HACS made adding the component really easy also. :slight_smile:

These new nodes sound awesome! I’ve been using MQTT as a middle-man to accomplish the very thing these now accomplish. I’m guessing these nodes will actually react faster than using MQTT.

I know my post Fixing slow Hue motion sensors in Home Assistant using Node-RED could definitely benefit from not requiring the user to have an MQTT server so I will have to update it and some other posts to reflect this.

Great job on the new release! :smiley:

Very nice!

The sensor node doesn’t seem to take INPUT attributes from msg.attributes or msg.payload.attributes. I get errors for the latter:

UnhandledPromiseRejectionWarning: TypeError: parsedMessage.attributes.value.forEach is not a function
    at EntityNode.onInput (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/nodes/entity/entity.js:188:44)

I’m passing

msg.payload = {    
    "state": msg.payload,
    "attributes": {
                'taco': 'yes'
    }
}

to the sensor node configured to accept state on msg.payload.state. Without attributes, it works just fine.

I dropped the ball on that. Thanks for reporting, it’s fixed on the dev branch and will be in the next release.

https://github.com/zachowj/node-red-contrib-home-assistant-websocket/commit/18849d917984d9449c241ca9a9312dcfdcb98ea6

2 Likes

Great! Thank You!

It is working well now. Thanks for quick fix.

I noticed input attributes are not combined with configured attributes. Instead, input attributes override ALL the configured ones. Having input taking the priority fits with the usual NR pattern, but could it be more precise, and only override any duplicates?

I only ask because I planned to configure all the static attributes in the node, and define any dynamic ones in the payload.

Obviously, either way is very usable (and appreciated), as I could just define all of them in the payload.

Hi.
Im running Hassio, and followed the installation guide, installed node-v12.13.1 and added :blush:

"npm_packages": [
  "git+https://github.com/zachowj/node-red-contrib-home-assistant-websocket#integration"
], 

to node-red configuration file.
But when I open Node-Red I cant find the new nodes. Why? :flushed:

This is excellent, are you going to push it to hass as an official component?

https://community.home-assistant.io/t/two-new-nodes-with-custom-integration-looking-for-testers/150736/22?u=kermit

Maybe at some point but right now this is only the first iteration.

2 Likes

I had planned to add different options on how to handle attributes and just forgot about it.

  • Override
  • Merge
  • Block Override

.

2 Likes

Hi
I’m trying to set a date and time for an input_datetime which is “now+24 hours”
I use the call service node with the following data field:

{
    "datetime": "{{ ((as_timestamp(now()) + 86400 ) | timestamp_custom('%Y-%m-%d %H:%M:%S')) }}"
}

however, I have the following error
"Call-service API error. Error Message: Invalid datetime specified: for dictionary value @ data['datetime']"

any idea of what is my mistake?
thanks!