Code Monkey home page Code Monkey logo

node-red-contrib-home-assistant's Introduction

Node Red Contrib Home Assistant

Various nodes to assist in setting up automation using node-red communicating with Home Assistant.

Project status

Project is going through active development and as such will probably have a few 'growing pain' bugs as well as node type, input, output and functionality changes. At this stage backwards compatibility between versions is not a main concern and a new version may mean you'll have to recreate certain nodes.

Getting Started

This assumes you have node-red already installed and working, if you need to install node-red see here

NOTE: node-red-contrib-home-assistant requires node.JS > 8.0 If you're running Node-Red in Docker you'll need to pull the -v8 image for this to work.

$ cd cd ~/.node-red
$ npm install node-red-contrib-home-assistant
# then restart node-red

If you are running Node Red inside Hass.io addon/container you can use Hass.io API Proxy address http://hassio/homeassistant as Home Assistant server address (server node Base URL). This way you don't need any real network address.

======= For flow examples checkout the flows here


Included Nodes

The installed nodes have more detailed information in the node-red info pane shown when the node is selected. Below is a quick summary

All Events

Listens for all types of events from home assistant

State Changed Event

Listens for only state_changed events from home assistant

State Trigger

Much like the State Changed Ndoe however provides some advanced functionality around common automation use cases.

Poll State

Outputs the state of an entity at regular intervals, optionally also at startup and every time the entity changes if desired

Call Service

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

Get Current State

Fetches the last known state for any entity on input

Get History

Fetches HomeAssistant history on input

Get Template

Allows rendering of templates on input


Development

An environment with Home Assistant/Node Red can be easily spun up using docker and docker-compose along with built in VSCode debug enabled.

  1. Clone this repository: git clone https://github.com/AYapejian/node-red-contrib-home-assistant.git
  2. Install node dependencies as usual: cd node-red-contrib-home-assistant && yarn
  3. Start the docker dev environment: yarn run dev a. Note: First run will take a bit to download the images ( home-assistants image is over 1gb (yikes!) after that launch is much quicker) b. Note: Also first run load of HomeAssistant web interface seems very slow, but after first time it's also much faster
  4. The yarn run dev command will leave you with a terminal spitting out logs, ctrl+c out of this and it kills all the servers by design, just run yarn run dev again to pick back up. The following services and ports are launched in the dev script
service port mappings info
home-assistant 8123:8123, 8300:8300 exposed for local access via browser
node-red 1880:1880, 9123:9229 exposed for local access via browser, 9123 is used for debugging. Includes default flow example connected to home-assistant

Docker Tips

  1. If you run into environment issues running yarn run dev:clean should remove all docker data and get you back to a clean state
  2. All data will be discarded when the docker container is removed. You can map volumes locally to persist data. Create and copy as directed below then modify docker-compose.yaml to map the container directories to the created host dirs below. See: ./_docker/docker-compose.mapped.yaml for an example or just use that file to launch manually
mkdir -p _docker-volumes/home-assistant/config
mkdir -p _docker-volumes/node-red/data
cp _docker/home-assistant/root-fs/config/* _docker-volumes/home-assistant/config/
cp _docker/node-red/root-fs/data/*  _docker-volumes/node-red/data

Node Debugger via VSCode

Optional but it's pretty nice if you have VSCode installed.

  • Open the project directory in VSCode
  • Go to the debug tab ( or cmd/ctrl+shift+d)
  • In the debug tab you should see an target for "Attach: Docker", run that guy and you can place debug breakpoints and changes will be reloaded within docker automatically
  • Open http://localhost:8123 for HomeAssistant (password is password by default).
  • For node-red either open up via the HomeAssistant web link or left hand menu or just open a browser tab to http://localhost:1880

Other Dev Tips

  • If you're using VSCode and annoyed that node-red html ( type="x-red" ) isn't syntax highlighted you can run force it by adding support. Below is for Mac, can do the same manually on any platform however, note that this is a hack as I couldn't find any other good way to do this.
# For VSCode
sed -i .orig 's/text\/(javascript|ecmascript|babel)/text\/(javascript|ecmascript|babel|x-red)/' "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/html/syntaxes/html.json"

# For VSCode Insiders
sed -i .orig 's/text\/(javascript|ecmascript|babel)/text\/(javascript|ecmascript|babel|x-red)/' "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/html/syntaxes/html.json"

node-red-contrib-home-assistant's People

Contributors

ayapejian avatar bodge-it avatar brubaked avatar darchambault avatar declankenny avatar drogfild avatar jamesgol avatar jason-nz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-red-contrib-home-assistant's Issues

Project management

@AYapejian do you want someone else to come alongside you to manage this project? it hasn't been touched an over 2 months, and it has a number of people trying to contribute. I'm not sure that i'm the best person for the job (not a programmer/don't know node, but i'd be willing to help out, or maybe someone else who has made a meaningful contributon to the project.

It just seems that more could e accomplished here than is currently happening.

Alternately, if you are not interested in continuing to maintain it, should the project be forked?

Automate dev environment setup

Use docker to automate the entire home assistant -> node-red -> node-red-home-assistant dev environment allowing easier setup and reproducing of issues.

Updated to 0.3.0 but all nodes are missing

I just updated to 0.3.0 and after restarting Node Red, all home assistant nodes are missing from all my flows, and from the left hand side. They still show as being installed, but none of my flows are working now.
screenshot from 2018-02-17 22-10-04

cannot get /home assistant/services

Hi

I can't get this to send any commands to HA. When I insert the
"Call service"-node the error "Cannot get /home assistant/services" flashes for a few seconds. I run this on a Rpi3 with Raspbian and HA on another Rpi3 with Hassio.

On the Hassio I added the Node-red component and there everything works great but on the other one I can only get messages from HA but not send anything back.

Does anyone have an idea on how to solve this? I'm guessing it has something to do with permissions but I have nog idea where to start looking.

Won't Parse Payload for Service

Docs suggest I should be able to send any/all of those to the node as an input and leave them blank in the node config. For example I want to specify the domain (light), and entity_id (kitchen_lights) in the config, but pass in the service "turn_on" or "turn_off" in the input message. Cannot figure out how to do this. I tried JSON {turn_on} but that isn't a full JSON statement and it doesn't like it. Tried just text, but it doesn't like that either. I get "Domain or Service not set, skipping call service". I don't know if this is an issue or I just don't understand how to format the payload input properly.

Exception in trigger:state node

The trigger state node causes a exception when userDir is not specified in config.js

01/03/2018, 09:20:52 node: Door opened
msg : string[48]
"Could not find userDir to use for database store"

This exception is thrown in base-nod.js in function async getDb() at row 72

let dbLocation = this.RED.settings.get('userDir');

A better way to read this property is
let dbLocation = this.RED.settings.userDir;

See node-red/node-red#1543

Current State not accurate

Using HassIO 0.66.1 and NodeRed addon 0.1.11.

I'm calling a lightbulb that is "on", yet the debug output will always show "off". I've tried this with various bulbs, and no luck. I've rebuilt and reinstalled NodeRed addon, and still having this issue.

Current State Halt On Inversed

I recently updated to the 0.2.1 version of this addon which fixed the crashes, but some of my flows stopped working. I figured out that if I use a "current state" node and set the "halt on" parameter, it is inversed in some cases. For example, I have a check for a motion event that looks at a light state. If on, the flow should halt. I noticed this kept saying "Halted Flow @ xxxx" when it should have proceeded though. I started manually changing states in Hass and checking the output and discovered if its set to halt on "On," it halts when the state is actually Off. This is happening on a number of flows.

The work around is leaving the halt on field blank and using switches, but this just adds unneeded mess to the flows. The other work around is to invert the halt on statement, but that adds confusion for troubleshooting.

Significant processing delay between node-home-assistant and node-red node.

There is a delay of ~2+ seconds from node-home-assistant processing an event to when node-red handles it in an event node on my rpi3 running hassio.

Using the npm ha package dashboard to compare, I noticed 1-3 seconds of delay between processing times. In total due to the node-home-assistant issue [AYapejian/node-home-assistant#4] we see 3+ seconds worth of delay from the source eventsream. I'm not sure exactly where all the delay originates, but I think a good step would be to profile the different parts.

Nodes disappear from palette after restart

I've tried installing from within the web page under "manage palette", and i've tried installing via npm... either way, after a restart of node-red, or reloading the page from scratch, the home assistant nodes no longer appear. It's listed in the palette manager, but I have to uninstall/reinstall to make them usable again.

unable to see nodess after reloding page <nodered_ip>:1880

hi. I think this is a good job and a grate idea! My issue is that, after installation of the nodes, it occurs that the nodes desappear from node list. if I have a node in my flow, after reloading the page the node is unrecognized even if the "node-red-contrib-home-assistant" contrib is installed. to see them again I have to uninstall ad reinstall the contrib. any idea why?

I have installed it through manage palette. nodered preinstalled on the latest noobs.

thanks
mp

Improve documentation

  • The internal node-red documentation for nodes needs some love
    • Pretty up the documentation here, look at the node-red docs for formatting best practices
  • Add example flows section of some simple ( hopefully common ) use cases

Receive a 404 for any calls

I receive an error trying to do anything with this and I am assuming it is because it is trying to call

/homeassistant/services, etc.

Which is not valid for my install at 0.58.2 since it uses the REST API at /api/

Has anyone gotten this working with a recent version?

Current state prefers payload entity_id instead of configured one

I started getting into Node RED automation with this plugin and my HA the last days. Unfortunately I struggled quite a lot since I used the "server events" node to get events. I then piped this into a "current state" node which was supposed to check another entity's state and halt if it was "off".

The problem is, that this "current state" node always uses the entity_id of the incoming payload instead of the one configured in the node itself. This means that it always checks the one of the output of the "server events" node's output. Is this intended and if so, why? When I specify an entity_id in the "current state" node, why is it not preferred? I think it would make sense to always use the configured entity_id unless it doesn't exist or is empty. However I'm afraid that it might break lots of existing flows...

If it's intended, I'd also suggest to document it somewhere. The documentation lacks basic details and one is forced to use the debug node and read through the JS code to find such things like described above.

history node not working

I know it says it is WIP, but it doesn't seem to be working at all at the moment. No string is saved and leaving it empty returns the following error: "Error calling service, home assistant api error".
You can tell no string is saved in the node, since if you write anything and save the node, you can't actually deploy the flow.

the plugin seems to be working great for all other nodes, so I just wanted to make clear people are actually using it and hoping for extra features :)

The mentioned ability to filter by entity_id would be great too (there doesn't seem to be any way to do that either atm)

Not possible to receive state from Home Assistant

Hi,
Its not possible to receive any state for input node from Home Assistant. Outputs works fine.

e.g. I can do some action with alexa local. But I cant receive a state of an motion sensor or a switch.

I always have an "Red Disconnected" on the input node.

As server URL I have to use http://hassio/homeassistant everything else does not work.

I run hassio on a raspberry pi 3 with node-red addon

The log shows this

22 Dec 21:07:11 - [error] [server-state-changed:Motion] Connection error occured with the home-assistant server: {"type":"error","status":504}
22 Dec 21:12:14 - [error] [server-state-changed:Motion] Connection error occured with the home-assistant server: {"type":"error","status":504}
22 Dec 21:17:17 - [error] [server-state-changed:Motion] Connection error occured with the home-assistant server: {"type":"error","status":504}

Thx for helping

add TLS support

at the moment the node can't connect to a home assistant instance secured by TLS.
specifying the url as https://hostname:8123 just throws a generic {error} in Node-Red debug window.

this is a node-home-assistant issue in fact. the version installed via NR built in palette uses axios as a client for http requests. (please advise if I have to open a separate issue)

Unfortunately I can't figure out how to patch in https/tls support (axios supports it (axios/axios#12) but the documentation is not clear to me) otherwise I'd have directly sent a PR, sorry.

Unable to install with npm install

Hi,
Newbie here (at least as far as node/npm/node-red goes).
I'm running HA and node-red on Linux box (Debian SID just updated). Fresh install of node-red (v 0.18.3). Attempting to install this package as HA user gives only this:

.node-red$ npm install node-red-contrib-home-assistant
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm WARN package.json [email protected] No license field.
npm ERR! git clone [email protected]:github:node-red/node-red undefined
npm ERR! git clone [email protected]:github:node-red/node-red undefined
npm ERR! notarget No compatible version found: node-red@'github:node-red/node-red#0.18.2'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["0.1.0","0.2.0","0.3.0","0.4.0","0.5.0","0.6.0","0.7.0","0.7.1","0.7.2","0.8.0","0.8.1","0.9.0","0.9.1","0.9.1-nocolors","0.10.0","0.10.1","0.10.2","0.10.3","0.10.4","0.10.6","0.10.8","0.10.8-2","0.10.8-3","0.10.9","0.10.10","0.11.0","0.11.1","0.11.2","0.12.0","0.12.1","0.12.2","0.12.3","0.12.4","0.12.5","0.13.0","0.13.1","0.13.2","0.13.3","0.13.4","0.14.0","0.14.1","0.14.2","0.14.3","0.14.4","0.14.5","0.14.6","0.15.0","0.15.1","0.15.2","0.15.3","0.16.0","0.16.1","0.16.2","0.17.0","0.17.2","0.17.3","0.17.4","0.17.5","0.18.0","0.18.1","0.18.2","0.18.3"]
npm ERR! notarget 
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! System Linux 4.14.0-3-amd64
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "node-red-contrib-home-assistant"
npm ERR! cwd /home/ha/.node-red
npm ERR! node -v v8.9.3
npm ERR! npm -v 1.4.21
npm ERR! code ETARGET
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/hassio/.node-red/npm-debug.log
npm ERR! not ok code 0

Thanks for any help

0.30 no longer shows timestamps/node status

I just recently updated to the 0.30 node and while it has a lot of great additions, one thing I miss are timestamps when events were triggered. I used to check timestamps in the flows (without debug nodes) periodically to see if they appeared to be working correctly. Can you add this if time permits? Low priority suggestion.

Not compatible with node-red 0.18.3

Hello

I installed node-red-contrib-home-assistant with node-red 0.18.3, the module is visible in node-red's palette but cannot be enabled.
Also no home-assistant nodes are showing up in the available nodes ...
Thanx for support

Any idea?

current state does not output requested data

I'm trying to use current state to get the attribute brightness_pct for a light so I can store it in a variable for later use, but every time it only returns "on" or "off". This seems to be the case for all the available outputs. Below is the flow in question.

[{"id":"5a6af2b.170250c","type":"api-current-state","z":"cdd927d6.f1cc08","name":"","server":"4f0a8cab.0253b4","halt_if":"","entity_id":"light.den","x":320,"y":460,"wires":[["cd1181c7.6e04a"]],"outputLabels":["data.attributes.brightness_pct"]},{"id":"e06e7a3f.b10cc8","type":"inject","z":"cdd927d6.f1cc08","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":460,"wires":[["5a6af2b.170250c"]]},{"id":"cd1181c7.6e04a","type":"debug","z":"cdd927d6.f1cc08","name":"","active":true,"console":"false","complete":"payload","x":550,"y":460,"wires":[]},{"id":"4f0a8cab.0253b4","type":"server","z":"","name":"Home Assistant","url":"localhost:8123:","pass":""}]

Use node inside of functions?

Hi,

is it possible to use for ex. the current_state node inside of a function? I'd like to get the sun.sun state for example inside of a function which is called by a presence detection to activate (or not) a light

Include payload value in service call data

I would like to send a notification using the notify/bot service that includes a value that I'm getting from a msg.payload. I tried all kinds of data fields. All combinations without quotes are not accepted by node-red, all others don't seem to work, like:

{ "message" : "{{ payload.temperature }}" }
{ "message" : "{{ msg.payload.temperature }}" }
{ "message" : "{{ msg.payload }}" }

Sending a simple message, using { "message" : "test message" } works, so i'm confident that the service is working, just confused how to include the correct payload value.

Any suggestions?

entity_id filter in the "events:states" node does not work

Hello, nice jobs you've done !

The entity_id filter in the "events:states" node does not work for me (it does not filter anything).

The problem seems to be in "node-server-state-changed.js" lines 59: it does not extract the entity_id but the event_type.

for instance in the Node-RED debug pane, I get:

object
  event_type: "state_changed"
  topic: "state_changed" <-- should be "sun.sun" according to line 61
  payload: object
    event_type: "state_changed"
    entity_id: "sun.sun"

and later in line 66, you're using the same wrong value ("state_changed" instead of "sun.sun") to match the filter and blacklist.

Can't install on new Node-Red docker

I just stood up a new node-red docker to test the newest version of this node - I can install the node, but after a restart of the docker container, I see this in the logs:
6 Mar 01:05:08 - [warn] ------------------------------------------------------
6 Mar 01:05:08 - [warn] [node-red/rpi-gpio] Info : Ignoring Raspberry Pi specific node
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/server] SyntaxError: Unexpected identifier
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/server-events] SyntaxError: Unexpected identifier
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/server-state-changed] SyntaxError: Unexpected identifier
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/trigger-state] SyntaxError: Unexpected identifier
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/poll-state] SyntaxError: Unexpected identifier
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/api-call-service] SyntaxError: Unexpected identifier (line:2)
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/api-current-state] SyntaxError: Unexpected identifier (line:1)
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/api-get-history] SyntaxError: Unexpected identifier (line:2)
6 Mar 01:05:08 - [warn] [node-red-contrib-home-assistant/api-render-template] SyntaxError: Unexpected identifier (line:2)

After everything loads - I can get into the node-red console and when I look for the HASS nodes to drag onto the screen, they are not there (they were there before the restart). It still shows the node to be installed when I manage the palette.

This is on node-red (using this image from docker hub nodered/node-red-docker:latest) - version 0.18.4. I'm using the latest version of this node as far as I can tell.

Edit: I tried 0.18.3, 0.18.2, 0.18.1, 0.18.0 as well. Results were the same each time. Docker is running on an Ubuntu VM on Proxmox. Docker is 17.12.0-ce.

Edit(2): I tried it on my QNAP (different Docker than my UBUNTU box) to make sure this wasn't something I had done wrong with Docker/rights etc on my UBUNTU box - same issue - running NR 0.17.5 container on the QNAP - he're log from QNAP:

6 Mar 16:47:33 - [info] Node-RED version: v0.17.5
6 Mar 16:47:33 - [info] Node.js version: v6.12.0
6 Mar 16:47:33 - [info] Linux 4.2.8 x64 LE
6 Mar 16:47:34 - [info] Loading palette nodes
6 Mar 16:47:36 - [warn] ------------------------------------------------------
6 Mar 16:47:36 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
6 Mar 16:47:36 - [warn] [server] SyntaxError: Unexpected identifier
6 Mar 16:47:36 - [warn] [server-events] SyntaxError: Unexpected identifier
6 Mar 16:47:36 - [warn] [server-state-changed] SyntaxError: Unexpected identifier
6 Mar 16:47:36 - [warn] [trigger-state] SyntaxError: Unexpected identifier
6 Mar 16:47:36 - [warn] [poll-state] SyntaxError: Unexpected identifier
6 Mar 16:47:36 - [warn] [api-call-service] SyntaxError: Unexpected identifier (line:2)
6 Mar 16:47:36 - [warn] [api-current-state] SyntaxError: Unexpected identifier (line:1)
6 Mar 16:47:36 - [warn] [api-get-history] SyntaxError: Unexpected identifier (line:2)

Also - mapping port 1881 to 1880 under Docker since node-red was already using 1880.

If I can answer more questions, grab more logs etc, please let me know,

Thanks for the work on the node, enjoy it a lot!!

#47

Auto complete not working

I just switched to using Node-Red inside Docker and have found that after installing the home-assistant component that auto-complete no longer works. I can successfully create new automations by manually typing the correct entries into the various fields, but the autocomplete never works for services, entities, etc. Any ideas how I can troubleshoot this?

cannot read property "state" of null

It looks like there's an unhandled exception state that's causing node-red to crash on my installation of HassIO.

6 Nov 23:33:51 - TypeError: Cannot read property 'state' of null
    at Object.onIncomingMessage (/data/node_modules/node-red-contrib-home-assistant/node-server-state-changed/node-server-state-changed.js:46:147)
    at HaEvents.onStateChanged (/data/node_modules/node-red-contrib-home-assistant/node-server-state-changed/node-server-state-changed.js:54:43)
    at emitOne (events.js:101:20)
    at HaEvents.emit (events.js:188:7)
    at HaEvents.onClientMessage (/data/node_modules/node-home-assistant/lib/ha-events.js:57:18)
    at EventSource.HaEvents.client.on (/data/node_modules/node-home-assistant/lib/ha-events.js:22:49)
    at emitOne (events.js:96:13)
    at EventSource.emit (events.js:188:7)
    at _emit (/data/node_modules/eventsource/lib/eventsource.js:186:17)
    at parseEventStreamLine (/data/node_modules/eventsource/lib/eventsource.js:201:9)
    at IncomingMessage.<anonymous> (/data/node_modules/eventsource/lib/eventsource.js:164:11)
    at emitOne (events.js:96:13)
    at IncomingMessage.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at IncomingMessage.Readable.push (_stream_readable.js:134:10)
    at HTTPParser.parserOnBody (_http_common.js:123:22)
npm info lifecycle [email protected]~start: Failed to exec start script
npm ERR! Linux 4.4.50
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" "--" "--userDir" "/data"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node $NODE_OPTIONS node_modules/node-red/red.js -v $FLOWS "--userDir" "/data"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node $NODE_OPTIONS node_modules/node-red/red.js -v $FLOWS "--userDir" "/data"'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the node-red-docker package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node $NODE_OPTIONS node_modules/node-red/red.js -v $FLOWS "--userDir" "/data"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-red-docker
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls node-red-docker
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/node-red/npm-debug.log

Call Service Node error with TTS

I was trying to use the call service node to trigger the Home Assistant TTS service to speak out my google home (chromecast).

It works fine directly in HA, and I've also succesfully tested it using postman. The error I get in the NodeRed log is: "Error calling service, home assistant api error"

Here is the simple node snippit I am testing with:

[{"id":"ae39b61c.121348","type":"inject","z":"24d5c164.203b5e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":560,"wires":[["b4c23eed.0b002"]]},{"id":"b4c23eed.0b002","type":"api-call-service","z":"24d5c164.203b5e","name":"","server":"ec4625c4.4c7b28","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.basement_speaker\",\"message\":\"Testing.\"}","x":540,"y":560,"wires":[]},{"id":"ec4625c4.4c7b28","type":"server","z":"","name":"Home Assistant","url":"http://localhost:3128","pass":"SecretPassword"}]

Custom Node-RED root path ignored

Summary

When trying to run Node-RED with a custom root path, some 404 errors appear when editing a flow with homeassistant nodes.

The only visible symptom is that autocomplete is broken and a red "404" error is displayed at the top of the page.
Manually filling-in the inputs seems to work fine.

Steps to reproduce

Setup

I've started from scratch on a Debian stretch box, and installed both node-red and node-red-contrib-home-assistant via npm :

node-red@HomeTest:/opt/node-red$ node -v
v6.12.3
node-red@HomeTest:/opt/node-red$ npm -v
3.10.10
node-red@HomeTest:/opt/node-red$ npm list node-red
/opt/node-red
└── [email protected]

node-red@HomeTest:/opt/node-red$ npm list node-red-contrib-home-assistant
/opt/node-red
└── [email protected]

(I've stuck to [email protected] to avoid 3.0 issues that are already logged)

No custom root path

After the fresh install, custom root path are disabled in the settings.js :

node-red@HomeTest:/opt/node-red$ grep "http.*Root:" /opt/node-red-data/settings.js
    //httpAdminRoot: '/admin',
    //httpNodeRoot: '/red-nodes',
    //httpRoot: '/red',

And Node-RED listens on /

node-red@HomeTest:/opt/node-red$ /usr/bin/node --max-old-space-size=128 /opt/node-red/node_modules/node-red/red.js --userDir /opt/node-red-data -v
19 Feb 11:00:34 - [info]

Welcome to Node-RED
===================

19 Feb 11:00:34 - [info] Node-RED version: v0.18.3
19 Feb 11:00:34 - [info] Node.js  version: v6.12.3
19 Feb 11:00:34 - [info] Linux 4.9.0-3-amd64 x64 LE
19 Feb 11:00:34 - [info] Loading palette nodes
19 Feb 11:00:35 - [warn] ------------------------------------------------------
19 Feb 11:00:35 - [warn] [node-red/rpi-gpio] Info : Ignoring Raspberry Pi specific node
19 Feb 11:00:35 - [warn] ------------------------------------------------------
19 Feb 11:00:35 - [info] Settings file  : /opt/node-red-data/settings.js
19 Feb 11:00:35 - [info] User directory : /opt/node-red-data
19 Feb 11:00:35 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
19 Feb 11:00:35 - [info] Flows file     : /opt/node-red-data/flows_HomeTest.json
19 Feb 11:00:35 - [info] Creating new flow file
19 Feb 11:00:35 - [info] Starting flows
19 Feb 11:00:35 - [info] Started flows
19 Feb 11:00:35 - [info] Server now running at http://127.0.0.1:1880/

When adding a simple Home Assistant Service node, an ajax call is sent to :
http://[domain]:1880/homeassistant/services
The autocomplete works fine.

Custom httpRoot

node-red@HomeTest:/opt/node-red$ grep "http.*Root:" /opt/node-red-data/settings.js
    //httpAdminRoot: '/admin',
    //httpNodeRoot: '/red-nodes',
    httpRoot: '/red',
node-red@HomeTest:/opt/node-red$ /usr/bin/node --max-old-space-size=128 /opt/node-red/node_modules/node-red/red.js --userDir /opt/node-red-data -v
19 Feb 11:14:57 - [info]

Welcome to Node-RED
===================
[...]
19 Feb 11:14:58 - [info] Server now running at http://127.0.0.1:1880/red/

In the Node-RED admin, called with "/red", the Ajax calls are still sent to http://[domain]:1880/homeassistant/services
Which generates Cannot GET /homeassistant/services

However, if I add the root path manually, it answers correctly : http://[domain]:1880/red/homeassistant/services

Custom httpAdminRoot

node-red@HomeTest:/opt/node-red$ grep "http.*Root:" /opt/node-red-data/settings.js
    httpAdminRoot: '/admin',
    //httpNodeRoot: '/red-nodes',
    //httpRoot: '/red',
node-red@HomeTest:/opt/node-red$ /usr/bin/node --max-old-space-size=128 /opt/node-red/node_modules/node-red/red.js --userDir /opt/node-red-data -v
19 Feb 11:28:19 - [info]

Welcome to Node-RED
===================
[...]
19 Feb 11:28:19 - [info] Server now running at http://127.0.0.1:1880/admin/

In the Node-RED admin, called with "/admin", the Ajax calls are still sent to http://[domain]:1880/homeassistant/services
Which generates Cannot GET /homeassistant/services

However, if I add the root path manually, it answers correctly : http://[domain]:1880/admin/homeassistant/services

Workaround

I'm running NGinx as a Reverse Proxy. Adding a custom location to proxy to Node-RED works :

location /homeassistant/ {
	proxy_pass http://localhost:1880/red/homeassistant/;
	...
}

location /red/ {
	proxy_pass http://localhost:1880/red/;
	...
}

History Node Enhancements

#11 fixed broken history node but the node only works with start-date. Supporting enddate, filter entity, relative dates ( -90min from 'now' ) should be supported.

Call Service Node: Allow batching service calls by incoming payload data

Batch service calls, something like below (needs fleshing out)

msg = {
    payload: {
        options: { throttle: { requestsPerSecond: 2 } },
        batch: [
            { domain: 'light',      service: 'turn_on',         data: { entity_id: 'light.light1' }   },
            { domain: 'switch',     service: 'turn_on',         data: { entity_id: 'switch.switch1' } },
            { domain: 'thermostat', service: 'set_temperature', data: { entity_id: 'thermostat.upstairs', termperature: 22 } }
        ]
    }
};
 

[api-call-service] SyntaxError: Unexpected token = (line:3)

Welcome to Node-RED

26 Nov 20:53:22 - [info] Node-RED version: v0.17.5
26 Nov 20:53:22 - [info] Node.js version: v4.2.6
26 Nov 20:53:22 - [info] Linux 4.4.0-62-generic x64 LE
26 Nov 20:53:22 - [info] Loading palette nodes
26 Nov 20:53:23 - [warn] ------------------------------------------------------
26 Nov 20:53:23 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
26 Nov 20:53:23 - [warn] [api-call-service] SyntaxError: Unexpected token = (line:3)
26 Nov 20:53:23 - [warn] [api-current-state] SyntaxError: Unexpected token {
26 Nov 20:53:23 - [warn] [api-get-history] SyntaxError: Unexpected token = (line:2)
26 Nov 20:53:23 - [warn] [api-render-template] SyntaxError: Unexpected token = (line:2)
26 Nov 20:53:23 - [warn] [server] SyntaxError: Unexpected token =
26 Nov 20:53:23 - [warn] [server-events] SyntaxError: Unexpected token = (line:2)
26 Nov 20:53:23 - [warn] [server-state-changed] SyntaxError: Unexpected token {
26 Nov 20:53:23 - [warn] ------------------------------------------------------
26 Nov 20:53:23 - [info] Settings file : /home/erik/.node-red/settings.js
26 Nov 20:53:23 - [info] User directory : /home/erik/.node-red
26 Nov 20:53:23 - [info] Flows file : /home/erik/.node-red/flows_ubuntu.json
26 Nov 20:53:23 - [info] Server now running at http://127.0.0.1:1880/
26 Nov 20:53:23 - [info] Waiting for missing types to be registered:
26 Nov 20:53:23 - [info] - server
26 Nov 20:53:23 - [info] - api-call-service
26 Nov 21:01:12 - [info] Stopping flows
26 Nov 21:01:12 - [info] Stopped flows
26 Nov 21:01:12 - [info] Waiting for missing types to be registered:
26 Nov 21:01:12 - [info] - server
26 Nov 21:01:12 - [info] - api-call-service

Cannot install node-red-contrib-home-assistant on Node-RED Hass.io Add-On

I'm trying to install node-red-contrib-home-assistant on a clean install of Node-RED Hass.io Add-On, but the install silently fails, and the node is still available as "installable" in the palette. This is the log I can see in hassio.

Also the node is not added to package.json which I guess it should be?

Log
[INFO] Creating /share/node-red folder
[INFO] Creating default settings
[INFO] Disabling SSL
[INFO] Updating IDE Users
[INFO] Adding IDE User admin
[INFO] Updating HTTP Node User
[INFO] Adding HTTP Node User admin
[INFO] Enabling Projects
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info lifecycle [email protected]~prestart: [email protected]
npm info lifecycle [email protected]~start: [email protected]
> [email protected] start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js -v $FLOWS "--userDir" "/share/node-red"
10 Mar 09:02:37 - [info] 
Welcome to Node-RED
===================
10 Mar 09:02:37 - [info] Node-RED version: v0.18.4
10 Mar 09:02:37 - [info] Node.js  version: v9.8.0
10 Mar 09:02:37 - [info] Linux 4.4.50 arm LE
10 Mar 09:02:38 - [info] Loading palette nodes
10 Mar 09:02:43 - [info] Settings file  : /share/node-red/settings.js
10 Mar 09:02:43 - [info] User directory : /share/node-red
10 Mar 09:02:43 - [warn] No active project : using default flows file
10 Mar 09:02:43 - [info] Flows file     : /share/node-red/flows.json
10 Mar 09:02:43 - [info] Creating new flow file
10 Mar 09:02:43 - [info] Starting flows
10 Mar 09:02:43 - [info] Started flows
10 Mar 09:02:43 - [info] Server now running at http://127.0.0.1:1880/
10 Mar 09:04:43 - [info] Setting active project : Hemmafloden
10 Mar 09:04:43 - [info] Flows file     : /share/node-red/projects/Hemmafloden/flow.json
10 Mar 09:04:43 - [info] Stopping flows
10 Mar 09:04:43 - [info] Stopped flows
10 Mar 09:04:43 - [info] Starting flows
10 Mar 09:04:43 - [info] Started flows
10 Mar 09:05:26 - [info] Installing module: node-red-contrib-home-assistant, version: 0.3.0

Repeatable Crash

Hello I was wondering if you could help me, I'm facing an issue where node-red is crashing daily with this component. Docker reports the following from the node-red log:

27 Feb 22:01:21 - [red] Uncaught Exception:
27 Feb 22:01:21 - TypeError: Cannot read property 'state' of null
at ServerStateChangedNode.onHaEventsStateChanged (/data/node_modules/node-red-contrib-home-assistant/nodes/serve
r-events-state-changed/server-events-state-changed.js:38:42)
at emitOne (events.js:121:20)
at HaEvents.emit (events.js:211:7)
at HaEvents.onClientMessage (/data/node_modules/node-home-assistant/lib/ha-events.js:59:22)
at EventSource.client.on (/data/node_modules/node-home-assistant/lib/ha-events.js:27:49)
at emitOne (events.js:116:13)
at EventSource.emit (events.js:211:7)
at _emit (/data/node_modules/eventsource/lib/eventsource.js:222:17)
at parseEventStreamLine (/data/node_modules/eventsource/lib/eventsource.js:237:9)
at IncomingMessage. (/data/node_modules/eventsource/lib/eventsource.js:200:11)

Can anyone help fix this for me as I'm unable to create a stable flow due to this stopping me from integrating Home Assistant and Node-Red.

Thanks,

Ben.

Can this work with SSL?

I have 40+ automations created that are working GREAT with your set of nodes, but today I decided it was time to get more secure in my system so I set up duckdns and lets encrypt (successfully as far as home assistant goes). As I expected all the nodes that have a server config item immediately went to disconnected but fixing the server address in the config to my new duckdns address doesn't work....they are staying disconnected. What am i missing here?

[node-api_current-state] merge outgoing message with incoming message

Would it make sense to merge the current status output message with the incoming message?

I'm adding some meta data to the incoming message before calling the current state node. I would like to use that meta data and the returned state to decide what to do next in the flow.

Pretty much

var stateMessage = { topic: entity_id, payload: currentState.state, data: currentState };
node.send(object.assign(msg, stateMessage));

Call Service Node - Data example text is misleading

When setting up a Call Service node, the example text for the Data field is:
{ entity_id: light.living_room }

This format simply DOES NOT WORK. You must use quotes around the key and the value in that JSON or it is rejected by HA. Hopefully no one else has to waste their time following an example format that is misleading.

Correct example:
{ "entity_id": "light.living_room" }

server-state-change node will listen to all events that start with configured entity_id

Version 0.21, Node-Red 0.17.5, Home Assistant 0.61.

Steps to reproduce:

Add any two entities in Home Assistant where one entity starts with the name of another entity_id.

Example:

input_boolean:
  node-red-test:
    name: 'node-red-test'
  node-red-test-two:
    name: 'node rest test two"

Create a server-state-change node for entity_id 'node-red-test' that goes to a debug node.

Toggle the state of 'node-rest-test-two' and you will see a event that comes through, even though it should have stricter matching.

[{"id":"a88fe394.568e9","type":"server-state-changed","z":"e0703c90.1a341","name":"node-red-test","server":"e2a02faf.48099","entityidfilter":"binary_sensor.node-red-test","haltifstate":"","x":180,"y":1173,"wires":[["65cb89b5.b8d458"]]},{"id":"65cb89b5.b8d458","type":"debug","z":"e0703c90.1a341","name":"","active":true,"console":"false","complete":"true","x":332,"y":1173,"wires":[]},{"id":"e2a02faf.48099","type":"server","z":"","name":"Home Assistant","url":"https://localhost:8123","pass":"XXXX"}]

Expected behavior - server-state-change nodes should have strict matching based on the entity-id and only send through events that match the entity_id exactly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.