Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 17 Error: 'ValidationError: target.entity_id" must be an array' #1247

Closed
Mossi777 opened this issue Jan 7, 2024 · 4 comments · Fixed by #1207
Closed

Version 17 Error: 'ValidationError: target.entity_id" must be an array' #1247

Mossi777 opened this issue Jan 7, 2024 · 4 comments · Fixed by #1207

Comments

@Mossi777
Copy link

Mossi777 commented Jan 7, 2024

Describe the bug

This error is generated when controlling a light entity with data sent from a function node to a call service node.

To Reproduce

Update to v17

Expected behavior

No response

Screenshots

Screenshot 2024-01-07 174156

Example Flow

[{"id":"6b5954701ed083ba","type":"server-state-changed","z":"861b2db73c59ae63","g":"41b12c920d2316bc","name":"Light Sensor Value","server":"3d996e19.7df08a","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"sensor.light_sensor","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"lightValue","propertyType":"msg","value":"","valueType":"entityState"},{"property":"dimming","propertyType":"msg","value":"auto","valueType":"str"}],"x":170,"y":60,"wires":[["bfa12e4a57dd66c7"]]},{"id":"bfa12e4a57dd66c7","type":"rbe","z":"861b2db73c59ae63","g":"41b12c920d2316bc","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"lightValue","topi":"topic","x":330,"y":60,"wires":[["2dfe13a707cea36f"]]},{"id":"5207d19c88263e4e","type":"mysql","z":"861b2db73c59ae63","g":"41b12c920d2316bc","mydb":"afaf0cde8eaddea4","name":"Read DB","x":580,"y":60,"wires":[["1b05c9f3f3a6f94a"]]},{"id":"1b05c9f3f3a6f94a","type":"function","z":"861b2db73c59ae63","g":"41b12c920d2316bc","name":"Light Control","func":"// Current ambient light level passed in to function\n//var currentLightLevel = Number(msg.lightValue);\nvar entities = {};\nvar transition = 60;\nvar brightness_pct = 0;\nvar triggerValue = 0;\nvar entity_id = \"\";\nvar ha = global.get(\"homeassistant\");\nvar dimmingMsg = msg.dimming;\nentities = msg.payload;\n\nentities.forEach(checkLightValue);\n\n/**\n* @param {{ ambientLightTriggerValue: any; entity_id: any; dimming: any; }} item\n*/\nfunction checkLightValue(item) {\n\n    var triggerValue = Number(item.ambientLightTriggerValue);\n    var entity_id = item.entity_id;\n    var dimming = item.dimming;\n\n    var currentLightState = ha.homeAssistant.states[entity_id].state;\n    var currentLightLevel = Number(ha.homeAssistant.states[\"sensor.light_sensor\"].state);\n    \n    if (msg.dimming == 'auto') {\n        dimming = item.dimming;\n    } else {\n        dimming = msg.dimming;\n    }\n\n    if(dimming == 1) {\n        if (currentLightLevel >= triggerValue * 1.1 && currentLightState == \"on\") {\n            //msg.payload = \">=\"; node.send(msg);\n            brightness_pct = 0;\n            msg.payload = sendControlMsg_dimming(brightness_pct, entity_id, \"turn_on\");\n        } else if (currentLightLevel < triggerValue && currentLightState == \"off\") {\n            //msg.payload = \"<\"; node.send(msg);\n            brightness_pct = 100;\n            msg.payload = sendControlMsg_dimming(brightness_pct, entity_id, \"turn_on\");\n        }\n    } else if (dimming == 0){\n        if (currentLightLevel >= triggerValue * 1.1 && currentLightState == \"on\") {\n            sendControlMsg_noneDimming(entity_id, \"turn_off\");\n        } else if (currentLightLevel < triggerValue && currentLightState == \"off\") {\n            sendControlMsg_noneDimming(entity_id, \"turn_on\");\n        }\n    }\n}\n\n/**\n* @param {number} brightness_pct\n* @param {any} entity_id\n* @param {string} service\n*/\nfunction sendControlMsg_dimming(brightness_pct, entity_id, service) {\n    msg.payload = {\n        \"service\": service,\n        \"target\": {\n            \"entity_id\": entity_id\n        },\n        \"data\": {\n            \"brightness_pct\": brightness_pct,\n            \"transition\": transition\n        }\n    } \n    node.send(msg);\n}\n\n/**\n* @param {any} entity_id\n* @param {string} service\n*/\nfunction sendControlMsg_noneDimming(entity_id, service) {\n    msg.payload = {\n        \"service\": service,\n        \"target\": {\n            \"entity_id\": entity_id\n        }\n    }\n    node.send(msg);\n} \n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":60,"wires":[["5ff33e2821458dc7","3e353c6bdf9baeb6"]]},{"id":"2dfe13a707cea36f","type":"function","z":"861b2db73c59ae63","g":"41b12c920d2316bc","name":"SQL","func":"var ha = global.get(\"homeassistant\");\n\n// Get Master Light Control Setting\nvar masterControl = ha.homeAssistant.states[\"input_select.lighting_control_master\"].state;\n\n// Get Night Inhibit Control Setting\nvar nightInhibit = ha.homeAssistant.states[\"input_boolean.night_inhibit\"].state;\n\n// Action While loop checking all dimmable lights based on the triggel light level set in the Admin screen\nif (masterControl == \"Auto\" && nightInhibit == \"off\") {\n    msg.topic = \"SELECT * FROM lights WHERE ambientLightControlled = 1 AND lightControlStatus = 'Auto' AND disableAuto = 0 AND presenceControlled = 0;\";\n    node.send(msg);\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":60,"wires":[["5207d19c88263e4e","2d73316bb1f51f44"]]},{"id":"5ff33e2821458dc7","type":"api-call-service","z":"861b2db73c59ae63","g":"41b12c920d2316bc","name":"Operate Light","server":"3d996e19.7df08a","version":5,"debugenabled":false,"domain":"homeassistant","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"{}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":60,"wires":[[]]},{"id":"3d996e19.7df08a","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},{"id":"afaf0cde8eaddea4","type":"MySQLdatabase","name":"","host":"localhost","port":"3306","db":"homeassistant","tz":"GMT","charset":"UTF8"}]

Environment Information

Version: 17.0.0

Home Assistant version: 2024.1.2
Companion version:

Node-RED version: 3.1.0
Docker: no
Add-on: no

Node.js version:
OS:

Additional context

reverted back to version 16 and all works fine

@chrismaki
Copy link

Same problem here, sending this JSON:

{
    "service": "turn_on",
    "domain": "light",
    "data": {
        "brightness_pct": 100
    },
    "target": {
        "entity_id": "light.front_foyer_lights"
    }
}

to a call-service node results in the same error. Once I reverted to 16.0.2 it started working again.

@zachowj
Copy link
Owner

zachowj commented Jan 9, 2024

The error is valid as the documentation shows the target properties are to accept arrays. The validation was fixed to check that the property value was an array. I'll change the validation to allow both strings and arrays.

@Mossi777
Copy link
Author

Mossi777 commented Jan 9, 2024

Thank you. 17.0.1 now works a dream.

@teamRibcage
Copy link

This fixed my issues as well - thanks for all the hard work! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants