Help Required to Format J: expression

I have an HA helper named ‘input_select.return_control_mode_to’. I would like to set the output payload of a ‘time node’ to the current state of that helper. I’ve set the output properties of the ‘time node’ to msg.payload with a J: expression of

global.get("homeassistant.homeAssistant.states['input_select.return_control_mode_to'].state")

but the output of the node is undefined.

Please help me format the J: expression so the current state of the ‘input_select.return_control_mode_to’ is output in the payload.

My complete flow is as follows;

Screenshot 2023-02-24 210304

[{"id":"49624df504212b7c","type":"ha-time","z":"c412c2ea.b8377","name":"End Vacation Mode - Phase I","server":"fcf9b76b.256a88","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.vacation_end_date","property":"state","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":" global.get(\"homeassistant.homeAssistant.states['input_select.return_control_mode_to'].state\")","valueType":"jsonata"}],"sunday":true,"monday":true,"tuesday":true,"wednesday":true,"thursday":true,"friday":true,"saturday":true,"debugenabled":true,"x":520,"y":860,"wires":[["7ad925eaf5c64e38"]]},{"id":"7ad925eaf5c64e38","type":"debug","z":"c412c2ea.b8377","name":"debug 62","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":760,"y":860,"wires":[]},{"id":"fcf9b76b.256a88","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Thanks in advance

$entities("input_select.return_control_mode_to").state

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

1 Like

Thank you. That works perfect.

I want to add an inject node for testing purposes. When the same expression is added to the node, an error occurs when the node is activated;

Attempted to invoke a non-function

Why would that be?

Functions linked in that jsonata guide are only available in HA nodes.

1 Like