Node-red-contrib-home-assistant-websocket

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!

I’m running hassio and websocket at version. 0.20 I tried ot update to version 0.3.1 but the install fails with this message:

image

Any suggestions? Tnx.

When using the hass.io add-on for node-red you are unable to update node-red-contrib-home-assistant-websocket via the manage palette menu, There was an update for the hass.io add-on today that is using the latest released version of node-red-contrib-home-assistant-websocket.

For future instances where you may want to use the latest version but the add-on hasn’t been updated yet you can add this to your add-on config.

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

Thanks, that worked great!

Just curious, why are these “no connection” messages appearing recently?

image

Before it would just show a generic API Error if the server responded that call-service was missing something or the connection to the server timed out. Now it shows No Connection if the connection status to the websocket was not equal to CONNECTED at the time of input on the node. The API Error still shows if the server responds with a error about the actually call-service call.

Basically means your last call didn’t go through because there was no connection to Home Assistant.

Is this something I should address and fix or is it something that will eventually be worked out bewteen HA and websocket? Seems like there’s a race condition between websocket, node-red and HA since this call happens almost immediately?

What’s triggering the flow? The start of Node-RED?

I am assuming the flow starts on the loading of Node-RED and it’s getting to the call-service node before Node-RED has finished connecting to HA. So yes, sort of a race condition from the looks of it.

If it fails the call-service it doesn’t retry it at the moment, I guess it could be a future feature.

In the next release the current-state, event-state, trigger-state, and poll-state nodes will have better logic for the halt if field. You’ll be able to compare the current state against if it ==, !=, <, <=, >, >=, contains a substring or in an array.

With this new feature, I can also add the ability to have an addition output added to these nodes. So that when it succeeds the half if check instead of just dying and not sending any messages on it could send the message onto the second output. Basically how the trigger node works now for the top two outputs. I seem to run into this use case a lot where I have an event-state node then followed by a switch node to check the state. This could save you from this issue.

I 'm justing trying to poll here to see if this might be something people are interested in me adding. It probably won’t be in the upcoming release but the next one after that if users are interested.

  • Interested
  • Switch Nodes work fine
  • Whatever

0 voters

1 Like

It’s great to see that you’re willing to continue to improve the tools available for HASS and Node-Red integration. Just figured I’d say thank you for your efforts!

2 Likes

Release v0.4.0

New Features

  • Ability to cast the state of event entities and payload to String/Number/Boolean

  • Changed halt if logic to be able to use different comparators to check the state for current-state, and events-state-change nodes

  • Poll-state now has halt if logic

Added

  • Added status times for success and error messages for the get template node (@jonathanadams)

  • Added timeSinceChangedMs to current-state, events-state, and trigger-state nodes entity.timeSinceChangedMs

Fixed

  • Autocomplete to use the correct entities/services if more than one server is setup (#49)

Since several users have asked about it I created a Buy me a coffee link. Don’t feel at all obligated to use it but all donations will be appreciated.

Buy me a coffee

3 Likes

@Kermit

I am starting to use the state trigger node. I am having difficulties passing a constraint when it comes to property values, previous or current state work.

This is the ss of the node

Screenshot_2018-12-10_22-35-25

Now the debug output

In txt

  null,
  {
    "topic": "media_player.lounge_tv",
    "payload": "playing",
    "data": {
      "event_type": "state_changed",
      "entity_id": "media_player.lounge_tv",
      "event": {
        "entity_id": "media_player.lounge_tv",
        "old_state": {
          "entity_id": "media_player.lounge_tv",
          "state": "playing",
          "attributes": {
            "volume_level": 0.11,
            "is_volume_muted": true,
            "media_content_type": "channel",
            "source": "Netflix",
            "source_list": [
              "Live TV",
              "Netflix",
              "YouTube",
              "YouTube Kids",
              "kodi"
            ],
            "friendly_name": "Lounge TV",
            "entity_picture": "/api/media_player_proxy/media_player.lounge_tv?token=19a32c6f0f72b648a4&cache=23536eadafd901ab",
            "supported_features": 20409
          },
          "last_changed": "2018-12-10T12:29:45.054776+00:00",
          "last_updated": "2018-12-10T12:30:55.300413+00:00",
          "context": {
            "id": "c276db2347ad43fd90f058d05ae03586",
            "user_id": null
          }
        },
        "new_state": {
          "entity_id": "media_player.lounge_tv",
          "state": "playing",
          "attributes": {
            "volume_level": 0.11,
            "is_volume_muted": true,
            "media_content_type": "channel",
            "source": "Netflix",
            "source_list": [
              "Live TV",
              "Netflix",
              "YouTube",
              "YouTube Kids",
              "kodi"
            ],
            "friendly_name": "Lounge TV",
            "entity_picture": "/api/media_player_proxy/media_player.lounge_tv?token=19a32c6f0f3aebd89385832b648a4&cache=d13081ed50bd22c7",
            "supported_features": 20409
          },
          "last_changed": "2018-12-10T12:29:45.054776+00:00",
          "last_updated": "2018-12-10T12:31:06.291476+00:00",
          "context": {
            "id": "e4d1015a91124555a8003a98f0367134",
            "user_id": null
          },
          "timeSinceChangedMs": 81246
        }
      }
    },
    "failedComparators": [
      {
        "constraint": {
          "id": "fssrmq8xxwu",
          "targetType": "this_entity",
          "targetValue": "",
          "propertyType": "property",
          "propertyValue": "data.event.new_state.attributes.source",
          "comparatorType": "is",
          "comparatorValueDatatype": "str",
          "comparatorValue": "Netflix"
        },
        "constraintTarget": {
          "entityid": "media_player.lounge_tv",
          "state": {
            "entity_id": "media_player.lounge_tv",
            "old_state": {
              "entity_id": "media_player.lounge_tv",
              "state": "playing",
              "attributes": {
                "volume_level": 0.11,
                "is_volume_muted": true,
                "media_content_type": "channel",
                "source": "Netflix",
                "source_list": [
                  "Live TV",
                  "Netflix",
                  "YouTube",
                  "YouTube Kids",
                  "kodi"
                ],
                "friendly_name": "Lounge TV",
                "entity_picture": "/api/media_player_proxy/media_player.lounge_tv?token=19a32c6f0f3aeb2b648a4&cache=23536eadafd901ab",
                "supported_features": 20409
              },
              "last_changed": "2018-12-10T12:29:45.054776+00:00",
              "last_updated": "2018-12-10T12:30:55.300413+00:00",
              "context": {
                "id": "c276db2347ad43fd90f058d05ae03586",
                "user_id": null
              }
            },
            "new_state": {
              "entity_id": "media_player.lounge_tv",
              "state": "playing",
              "attributes": {
                "volume_level": 0.11,
                "is_volume_muted": true,
                "media_content_type": "channel",
                "source": "Netflix",
                "source_list": [
                  "Live TV",
                  "Netflix",
                  "YouTube",
                  "YouTube Kids",
                  "kodi"
                ],
                "friendly_name": "Lounge TV",
                "entity_picture": "/api/media_player_proxy/media_player.lounge_tv?token=19a32c6f0f3dfsfdas90efa872b648a4&cache=d13081ed50bd22c7",
                "supported_features": 20409
              },
              "last_changed": "2018-12-10T12:29:45.054776+00:00",
              "last_updated": "2018-12-10T12:31:06.291476+00:00",
              "context": {
                "id": "e4d1015a91124555a8003a98f0367134",
                "user_id": null
              },
              "timeSinceChangedMs": 81246
            }
          }
        },
        "comparatorResult": false
      }
    ]
  }
]

For your constraint check against new_state.attributes.source is Netflix. The top level is already at data.event.

1 Like

I updated homeassistant to 0.84.1 and Node-red-contrib-home-assistant-websocket to 0.43 and now my device tracker only outputs ‘undefined’ when I check the presence with ‘current state’ or ‘events state’.

Did something change that I’m not aware off?