How to read a sensor with a homey script

I’m not sure why you’re using device.state, AFAIK that property doesn’t exist.

Reading the current value of a capability from Homeyscript was discussed here.