Trying to read the value of hass-variable in a python_script ... how to do it?

Can anyone tell me how to read the value of a hass-variable from within a python_script? I’m not talking about a regular script (with jinja expansion.) There is a service available to set the values, but it doesn’t seem like I can get the current value in any normal way. Would appreciate some help…

I’m currently trying a direct call to hass.states.get, but it’s not giving me something that works.

lock = hass.states.get(“variable.” + str(lock_entity))

The variable is a “boolean” taking on only True or False. The get I’ve shown never seems to return anything - not sure if it returns the “state” or the “value”.

Thanks in advance

hass.states.get() returns a State Object. If you want the current “state string”, then you should use hass.states.get(entity_id).state.

2 Likes

Thanks that worked fine for me for an input_boolean. I tried something like that with a hass-variable and I had issues (I’ll try again.)