Node-red-contrib-home-assistant-websocket

Also, in the Hass.io version, I got a login screen that asked for my HA user credentials. I don’t get that now.

Looks like you pretty much made it almost all the way there. For the benefit of others did you see the Information Panel when you were in the config server window? If so do you feel that needs improvement in explaining the different fields?

I am going to assume you’re running Node-RED and Home Assistant on the same server because you said you’re running Hassbian.

Base Url is the web address you use to access the Home Assistant frontend (e.g., http://192.198.x.x and http://example.duckdns.org). In your case since you’re running Node-RED on the same server as Home Assistant, you could also use http://localhost:8123

I would say the preferred method to connect to the API of Home Assistant now is to use a Long-Lived Access Token. Use this guide on the Github wiki page to generate one and enter that token in the correct field.

Once you enter the base URL and the Long-Lived Access Token Update/Save the server config and deploy your flows. This first deploy will access Home Assistant and import all the entity ids and services which will allow the autocomplete to work when filling out nodes. Also, it will allow you to see if you have entered the information correctly by making sure your first node connects to Home Assistant.

1 Like

That’s part of the Node-RED config checkout Redirecting… for how to add authentication to Node-RED.

All hail the LONG-LIVED ACCESS TOKEN!

Thanks Kermit! :heart_eyes: I’ve switched over from the maybe abandoned project of @Ayapejian and only had to adjust a few nodes in my setup.

Hi all.

I currently have a Home Assistant (Hassbian) instance that is setup with duckdns and lets encrypt certificates. My Node-red instance is http and just setup for local access. Both instances are run from a RPi3.

To get my setup working, I’ve edited my hosts file to redirect my duckdns site to my local IP. This was entered into the node-red server config as ‘https://mysite.duckdns.org:8123’ along with my long-lived access token.

Right now the only node that doesn’t seem to work is the ‘call-service’ node. An error message appears just under the node saying ‘API Error’ and the debug log says “Error calling service, home assistant api error”.
Throughout this, Homeassistant does not display any messages in the log.

Any help on this would be greatly appreciated :slight_smile:

Can I see an export of your call-server node? Also if you don’t want to have to define your duckdns address in the local host file you could use “Accept Unauthorized SSL Certificates” under the server config to accomplish the same thing.

Sure! The call-server node export is below.

[{“id”:“20486e5a.e90832”,“type”:“api-call-service”,“z”:“c4b91bb3.2a9bb8”,“name”:“Jack => Just Left”,“server”:“f94f7fd7.2bc9f”,“service_domain”:“input_select”,“service”:“select_option”,“data”:“{ "entity_id": "input_select.jack_status_dropdown", "option": "Just Left" }”,“mergecontext”:“”,“x”:491,“y”:272,“wires”:[[“19349cf3.090083”,“6f64a672.71e7d8”]]},{“id”:“f94f7fd7.2bc9f”,“type”:“server”,“z”:“”,“name”:“Home Assistant”,“legacy”:false,“hassio”:false,“rejectUnauthorizedCerts”:false}]

Oh, I assumed that was for self signed certs! That’s really cool.

That’s really weird export, it has three different type of quotes and the data property JSON is not escaped. Try importing the below call-service node and testing that.

[{"id":"7de64ed5.ce4ec","type":"api-call-service","z":"2802ff38.60d4c","name":"Jack => Just Left","server":"43502601.1b2f48","service_domain":"input_select","service":"select_option","data":"{\"entity_id\":\"input_select.jack_status_dropdown\",\"option\":\"Just Left\"}","mergecontext":"","x":510,"y":660,"wires":[[]]}]

Thanks for the help.

I actually imported it from here - https://philhawthorne.com/making-home-assistants-presence-detection-not-so-binary/#comment-3945751887

I’ve imported your suggestion but unfortunately have the same error as before.

I tried creating a simple call-service node but it throws the same error.

[{"id":"62e379a5.76f498","type":"api-call-service","z":"c4b91bb3.2a9bb8","name":"","server":"f94f7fd7.2bc9f","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.livingroom\"}","mergecontext":"","x":511.5,"y":445,"wires":[["6f64a672.71e7d8"]]},{"id":"f94f7fd7.2bc9f","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false}]

If you deploy an event-state node or poll-state are they showing connected under them? Can you post your node-red log?

Ok, just added a poll-state and event-state node and they both connect fine.

Log is here: https://pastebin.com/p4FTZPu7

@thraker My guess is you might have another “server” configuration setting configured. Check from upper right hamburger icon -> Configuration Nodes. See if you have several “Home Assistant” server config. Find the one that has the error and delete it.

Thanks for the suggestion but no luck. I definitely only have one server config set. I just deleted and recreated that one to double check also with no change.

Just really strange that the only node that won’t connect is the call-server node…

Think it’s working now…deploying initially throws the error but if you start the chain of events that activates the node it all works fine. Used the inject node to test and also works.

Still not sure why the node has issues on deployment…? All working now anyway! Thanks for the help :slightly_smiling_face:

From looking at the logs the reason the error appears at the start then works, later on, is that it’s running the call-service node before the Node-RED has actually connected to Home Assistant so it’s showing the API Error. Then after it actually connects to the Home Assistant and runs the flow again it successful without the error.

First, I wanted to thank you for getting something like this together! I’m hoping that this will be extremely useful to those with less programming experience get into this field even more.

I’ve just started dabbling in HASS on the Raspberry with Node-Red. I spent a few hours getting it set up (lack of experience on my part) and I finally have node-red talking with home assistant. I’m running both node-red and HASS on the same Pi using the LTS method of authentication. Unfortunately, when I’m running node-red I’m receiving the following errors from HASS every 3 seconds.

aiohttp.http_exceptions.BadStatusLine: invalid HTTP method
2018-11-18 21:33:26 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 242, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp\_http_parser.pyx", line 523, in aiohttp._http_parser.HttpParser.feed_data

I’m able to do basic calls right now to turn off and on a few lights. I’m in the process of starting small and working my way in. Any help resolving the error message would be greatly appreciated. Thanks!

Release v0.3.1

New Features

  • Entity Id now has autocomplete for the Call Service node.

  • Trigger node now can be filtered by substring/exact/regex.

  • Call Service and Fire Event nodes are now able to render mustache templates in the data property. Templates also work on the new entity id field for the Call Service node.

Added

  • Request/Sending status to Call Service, Fire Event, Get History and Get Template nodes.

Changed

  • Call Service node won’t send message until it receives a response from HA.

  • Fire Event node won’t send message until it receives a response from HA.

4 Likes

I don’t believe this is directly related to this node-red module. Unless you’re using https:// to connect to a non-SSL home assistant.

Take a look at these threads:

Thanks for responding and for staying current with this node-red module. I ended up restarting the Pi and all seems to be working now without any issue! Thanks again!