Getting input_number state

I am trying to read an input_number state to save into a global variable to be accessed later. Everything I have tried has not worked. Based on several examples I have found googling, this should work, but doesn’t

const states = global.get('homeassistant').homeAssistant.states;
const bbr_ap = states['input_number.hasp_bbr_plate_activepage'].state;

While it works sometimes, I get the following error in the debug node.

2/17/2020, 2:01:43 PM[node: 5994520d.0c233c]
( : (error)

"TypeError: Cannot read property 'state' of undefined"

I am using a function node to get the data. Is this the wrong way of doing it? Why does it work sometime and not others?

EDIT: It seems it maybe a timing issue. When I trigger it after deploying, I get the error. If I wait a few seconds, it works.