Query entities from Function node

I love Node Red, and I’m beginning to get some grip on the programming model.
I’d like to write a JavaScript function in NR that inspects the state or attributes of HA entities.
Is that possible?
E.g. if I want to loop through all light entities in HA and check their status (on/off/%).
Or check the battery status of all battery devices.


If you’re looking to do a simple comparison you might want to look at the get-entities node. For more complex things there’s an example on how to access the global context homeassistant variable on the info panel of the server config node.