Cannot wrap my head around what I need to do here. Trying to wrap a python service call that isn’t designed to handle multiple entity ids, into a script. But I cannot figure out how to send a variable if and ONLY if it’s defined.
The code: (the count and entity_id templates are working and can be ignored, all they do is create a dict full of every entity id that follows the filter.)
The error I’m getting is usually something like ‘max_brightness expected int got None’ since it’s the first variable that is optional.
I’ve tried filtering with default(None), default(unknown), even tried sending an int out of range default(-1) to see if i could bypass it somehow. No dice. Also tried declaring different variables in the ‘variables’ section of the script and sending those. Didn’t work either.
I realize this is probably out of the scope of what I should be doing with Home Assistant but:
I really don’t want to rewrite the python function
I do not want to have every single service call written out for every possible amount of variables sent to the script.
Please help.
To reiterate, apparently the way Home Assistant service calls work is if a variable inside of data is specifically written, it will attempt to parse that variable, even if it’s (None, unknown, or not EVEN defined?)
But I need it to be null (or none or whatever) so the python integration uses its stored value, otherwise it’s setting the max brightness as 0 or whatever value every time if it’s not specifically defined in the parent service call.
There is no entity id that contains these values, they’re solely stored in an unreachable spot inside of adaptive lighting. What I need is to send null or none or unknown or whatever this syntax calls null so adaptive_lighting.change_sunlight_settings will use its values upon receiving None.
error: expected int for dictionary value @ data[‘min_color_temp’]. Got None
it’s like home assistant is completely overriding any detection of null and forcing its syntax before it gets anywhere near the service call. I get that this is more noob friendly approach but it’s seriously limiting this script’s potential.
It seems as though if a variable like ‘min_color_temp’ is defined anywhere in the service call, even if the value is None or Null or “” it’ll expect a valid value within the range.
so my question is: WTH is it sending when a variable like ‘min_color_temp’ is completely OMITTED from the service call? I’m still able to check against None/null in the python integration if that value is omitted so why can’t I just send that null value inside the script?
It is the adaptive_lighting.change_sunlight_settings service call that is expecting an integer value. Home Assistant doesn’t care what data you pass to the service. If you are defining the variable in this service call then it needs to be an integer. The service handles what to do if it’s not defined.
You can use a choose structure to define and choose service calls depending on the variables being used, but you have a lot of variables there that would be really messy.
I guess you could try build a dynamic dict of parameters/values as a variable and pass that to the service data. I think that would work? I’ve never tried it.
Is there really no way to explicitly undefine a variable if it evaluates to none?
How exactly would I build a dynamic dict of parameters?
It sounds like you’re saying I’d have to have a separate choose option for each amount of dynamic arguments passed to the script, which means I’d have 14 different choose options all with repetitive code. Is that really the only way to accomplish this?
@th3w1zard1 I made a small edit. ‘is defined’ should be changed to == empty for the sunrise/sunset variables. I made the change on this post. Just wanted to make sure you saw the edit.
I’m honestly sorry I went AWOL on this thread. I don’t know why I never tried this, I guess I gave up on the idea. I ended up doing this the long way and just reducing the variables to the ones I needed.
Fast forward to today, and, well I just rewrote the change_sunlight_settings() call to use another function and once again I was having this problem, googling around and I was surprised to find my own thread.
Anyway, just tested your changes a year later and they work BEAUTIFULLY. THANK YOU SO MUCH!!!