How to get a device status and populate a variable to use in a flow

Hi,

Who can help, since I am bad in J scripting, to create a working Homey script.
From a number of devices I like to compare the onoff states in several flows and pass the result back to that Homey flow. Am really looking for some coding which I can use.

Eg.
Device A, onoff state is off
Device B, onoff state is off
Device C, onoff state in on
Then return to the flow True, else False.
So, not looking for device volume, light intensity or humidity. Only looking at onoff state.

Use;
A flow calls the script “DeviceStatusXYZ” and on the return value the flow will continue or stop.

I managed to read devices (thanks to the forum)
Managed to read flow status (as well copy paste)

But due to inexperience in JS cannot get the logical in the script there. How to Get (?) or Read (?) an onoff state? How to read the right value of a device … Tried to start with device.capabilities but then? I can start with Object.values(devices).forEach(device => … but then? How ?

And how do I send the evaluated response (false/true) back to the flow?
Or; can I set a script related logical variable from wich I can read its value with a flow?
Or; trigger a script by a flow which sets a logical value which is read by another flow…

Many thanks for concrete examples. (The read aloud hour every hour example is to limited for me)

And to be honest; my intention is not to become a scripter in Java. I have now spend a couple of evenings going thru tutorials and experimenting. Nice is to see results (getFlowTokens or device ID’s) but very hard to make a step in dealing in content of variables, not knowing what error messages do mean or to make cheese (that’s my Dutch) of unexpected results.

Help is welcome and appreciated.
Rolf

Example query output - Like to read the onoff status (true, false) from shown below;

‘652d4bec-7216-468b-9da9-9a74c0de89b3’: t {
__athom_api_type: ‘HomeyAPI.ManagerDevices.Device’,
id: ‘652d4bec-7216-468b-9da9-9a74c0de89b3’,
name: ‘Main Zone’,
/*
*/
energy: null,
energyObj: { W: null, batteries: null, cumulative: null, generator: null },
virtualClass: null,
capabilities: [ ‘onoff’, ‘volume_mute’, ‘volume_down’, ‘volume_up’ ],
capabilitiesObj: {
onoff: [Object],
volume_mute: [Object],
volume_down: [Object],
volume_up: [Object]

Hello,
I was trying something similar and you should be able to use device.capabailitiesObj.onoff.value to get the value of the ‘onoff’
Hope that helps