NR doesn’t do anything with jinja2 templates other than pass them to HA. Does it work inside the template editor in HA?
Yep. It worked as an automation just fine and works in the template editor.
New Release v0.15.0
Bug Fixes
-
get-entities: error when property value was not set for jsonata (5125821)
-
trigger-state: Attribute of other entity undefined in trigger (a45366f), closes #148
Features
@Kermit if you have a spare minute could you please explain what the api node would be used for? Is it for some more advanced use cases?
I use the API node to grab camera images to feed them to telegram
I am trying to understand what websocket calls are possible and what the json looks like. There just isn’t much in the docs.
I can use
{“id”:3,“type”:“get_states”}
to get all states, but can I get the state for a single entity_id. What would the json be in that case?
I can turn on a thermostat with
{“id”:24,“type”:“call_service”,“service”:“turn_on”,“domain”:“climate”,“service_data”:{“entity_id”:“climate.therm”}}
but I don’t have a clue what the json would look like to change the temperature.
Any help would be appreciated.
Seems like it’s just a way to make custom API calls for things that aren’t already exposed as their own nodes.
@Kermit do you plan on supporting the new Device Triggers/Conditions/Actions? Would be super helpful for ZHA (zigbee)!
Speaking of new things, could writing the service call data by in yaml instead of json?
@RyanEwen I just took a quick glance at the new device automations and not exactly sure how those would translate to node-red. They look like they just fill in the normal automation page with details of the device you click. I don’t use zigbee so maybe they do more than what they do for my z-wave devices.
I hadn’t tried them myself but I did a quick one just now and my trigger for a Zigbee button press is much simpler:
trigger:
- platform: device
domain: zha
device_id: 807b25ebbb5e432aba705c526c94b461
type: remote_button_short_press
subtype: right
That used to require subscribing to zha_events
and watching for the desired device’s MAC access, the command
, and any device-specific args, all of which had to be figured out using the developer tools and pressing the buttons and noting what happens. Actually here I found someone else’s trigger for the same button press:
trigger:
platform: event
event_type: zha_event
event_data:
device_ieee: '00:0d:6f:ff:fe:62:50:cf'
command: 'press'
condition:
- condition: template
value_template: '{%if trigger.event.data.args==[0, 1, 13, 0]%}true{%else%}false{%endif%}
This is an IKEA 5 button remote where both left
and right
come in as the same command, and then you differentiate them by inspecting the args
data which is an array
New Release 0.16.3
Bug Fixes
-
check for WS client before listening for events (8d72dbc), closes #158
-
css changed for NR v1.0 (41539d7)
-
Remove event type from sub list when unsubscribing (321561d)
-
config-server: Revert ha_events for state_changed event so global context gets updated (ef0c8d1)
Features
-
call-service: Add debug flag for more information (873603b)
-
wait-until: Add trigger time to wait until node in status message (eeac869), closes #157
-
Add ability to disable caching of autocomplete results (a90e041)
Hi,
I’m new to using NodeRed but I’ve been using HA for a long time. I’m hoping I can get some help in setting up this Component as I’d like to experiment with nodered.
I have HA set up in a Docker Container and NodeRed set up in another Docker Container, both on the same Synology NAS.
I have node-red-contrib-home-assistant-websocket Version 0.16.3 set up in NodeRed
I have set up HA using ssl and have it working on
https://mydomain.duckdns.org
Note that it isn’t “mydomain” but I replaced my actual domain name
Please can you tell me what to set in the HA config for node-red-contrib-home-assistant-websocket Base URL entry
So far I’ve tried:
mydomain.duckdns.org
mydomain.duckdns.org:443
https://mydomain.duckdns.org
https://mydomain.duckdns.org:443
ws://mydomain.duckdns.org
wss://mydomain.duckdns.org:443
The last 2 crash nodered so I assume that they are no where near correct.
The first 4 give me the same error in NodeRed. I have a “debug” connected and every time it says “Connecting” and then “Disconnected”. I have logger turned on in HA as follows and nothing appears from the nodered attempts
logger:
default: warning
logs:
homeassistant.components.websocket_api: debug
I’m quite OK at writing python and I downloaded and altered the following script and it worked and connects. I am running it on my Windows 10 PC in a powershell.
#!/usr/bin/python3
#
# Copyright (c) 2017-2018, Fabian Affolter <[email protected]>
# Released under the ASL 2.0 license. See LICENSE.md file for details.
#
import asyncio
import json
import asyncws
import ssl
print(ssl.OPENSSL_VERSION)
ACCESS_TOKEN = 'deleted to post here'
async def main():
websocket = await asyncws.connect('wss://mydomain.duckdns.org:443/api/websocket', ssl=ssl.SSLContext())
await websocket.send(json.dumps(
{'type': 'auth',
'access_token': ACCESS_TOKEN}
))
await websocket.send(json.dumps(
{'id': 1, 'type': 'subscribe_events', 'event_type': 'state_changed'}
))
while True:
message = await websocket.recv()
if message is None:
break
print (message)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
The output on the display is
OpenSSL 1.1.0j 20 Nov 2018
{"type": "auth_required", "ha_version": "0.100.3"}
{"type": "auth_ok", "ha_version": "0.100.3"}
{"id": 1, "type": "result", "success": true, "result": null}
And then lots of data etc etc etc
Edit: forgot to say that I’ve also tried
http://mydomain.duckdns.org
And it says “connecting” all the time but I assumed this wouldn’t work as it wouldn’t know to connect using ssl. Anyway, it doesn’t seem to work either.
Also I have Node-Red version 0.19.4 and Node.js version 8.12.0 with Yarn Version 1.9.4. I installed the Synology Docker “nodered/node-red-docker” version 8.
Any help would be appreciated
Should just be https://mydomain.duckdns.org or https://mydomain.duckdns.org:443. A local address might work for you too.
You can also try the flow in the link below and replace the address with wss://mydomain.duckdns.org:443/api/websocket
Thank’s for the tips, I worked out what it was. I needed to tick the “Accept Unauthorized SSL Certificates” tick box.
Hi,
Does anyone know if its possible to set the entity_id via a payload for get_history? something like
edit: @Kermit -
I tried your suggestion from a different node, leaving it empty and setting the msg.payload.entity_id,
but its not working, any ideas?
thanks in advance!
Check the information tab of the get history node it shows msg.payload.entityid
as the input to change the entity id.
@Kermit Hi,
I do not see that anywhere in the information tab of the get history node.
also, leaving the field empty in the UI and putting this in a function node before does not work
msg.payload = {
entity_id:STRING
};
this also doesnt work
msg.payload = {
entityid:STRING
};
Leaving the field empty in the UI causes it to load the history of all entities in hass
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.
@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!!