I have a lutron caseta plug that is technically a light but it’s dimmable. I had my little window box fan working perfectly with it until all the changes, I can get it to turn on and off, but any preset calls or percentage calls do nothing. Attaching my code snippet. I would be grateful for help. Ignore the rem’d out lines, I left them behind so I could use them for reference when making the new sections.
Thanks for sharing. I was stuck trying to convert my Inovelli LZW36 Fan/Dimmer switch to the new format and this works perfect for that device. I am also getting errors, I checked the {{ (state_attr('light.inovelli_lzw36_fan_dimmer','brightness')/255*100)}} using Developer Tools->Template and the three speeds didn’t round out but instead would be 33.33333333333333, 65.49019607843137 and 100. I filtered it through | int and it’s rounding the numbers out to 33, 65 and 100 but still throwing errors in the log.
Hopefully someone else can chime in on what’s missing. Here’s the error:
TemplateError(‘TypeError: unsupported operand type(s) for /: ‘NoneType’ and ‘int’’) while processing template ‘Template(“{{ (state_attr(‘light.inovelli_lzw36_fan_dimmer’,‘brightness’)/255*100) | int}}”)’ for attribute ‘_percentage’ in entity ‘fan.living_room_fan’
I also have many LZW36’s, would you mind tagging me once you get something working great? For now I just swapped back over to the default light entity.
And/or post up in the inovelli forums, I think that would be a great post over there.
This is working 100% functionally speaking it’s just the error in the log. It doesn’t seem to stop any function.
It looks like the error is occurring due to the off state, Dev Tools->Template gives same error when the device is off. If the device is on everything passes (the 33, 67 and 100 values)
GitHub issue was closed citing not an error but was told
Brightness is not available as an attribute for lights when lights are off:
You can use default to help with that: "{{ ((state_attr('light.inovelli_lzw36_fan_dimmer','brightness') | default(0)) / 255*100 ) | int }}"
Yeah, not sure where to go from here, I mean I think it’s a bug, they say it’s not, but wont provide a valid config to prove that. I guess I’ll just live with the errors. I’m all for progress and moving forward but when things like this come up it’s frustrating.
@cybergrimes I just stumbled upon this thread. I just found out I am in the same bucket as you in regard to the lzw36 fan/light switch. If you figure out a solution please post it back here.
It’s really anyone who uses a fan template based off a light switch device sadly. I guess positive side is that it actually works 100% just the error in the logs is all.
Thank you, that coding works perfectly! I really wish there was some explanation as to why/how things like this are needed. As someone who is not a coder by trade these things make it really hard to be an “enthusiast”. I’m not an idiot either, I’m a systems engineer by trade.
The biggest thing to remember is that all states are strings. And some attributes are strings. Even tho they could look like something else.
So it’s always a safe bet to explicitly do the conversion to what you expect it to be.
but also the error gave you a hint of what the problem was:
unsupported operand type(s) for /: ‘NoneType’ and ‘int’
that means that you are trying to do a math operation (division) on two operands that don’t support it because one is an ‘int’ and the other one has no data type.