Open zimmra opened 3 months ago
@zimmra thanks for figuring this out, sorry for the delay responding. I'll try to get this in the main branch. I'll see if I can get the Savant version and switch behavior based on that.
@zimmra finally getting around to this. I did some more digging and found the actual definition of how the load state numbers are derived in my version:
function getSetStateValue(id) {
return (service.intAddress << 16 | id - 1 & 1023).toString(16)
}
If you have time, could you look through the Web UI source (via Chrome's inspector) for a similar function getSetStateValue
? Mine was in LoadLevelService.min.js
. That should give the exact formula, I suspect it's hex-based as well. Then I can add a switch in the config object for which load state "mode" to use.
I might have figured it out, yours seems to be bit-shifted by 7 instead of 16 (and I'm assuming the Load ID is being adjusted similarly), giving something like this?
function getSetStateValue(id) {
return (service.intAddress << 7 | id - 1 & 127).toString(16)
}
@zimmra I pushed a branch that might work for you, haven't had time to test it myself though: https://github.com/thetoothpick/savant-lighting-hacs/compare/main...light-load-state-name
I might have figured it out, yours seems to be bit-shifted by 7 instead of 16 (and I'm assuming the Load ID is being adjusted similarly), giving something like this?
function getSetStateValue(id) { return (service.intAddress << 7 | id - 1 & 127).toString(16) }
You were on the right track. Here is what I see in my LoadLevelService.min.js
getSetStateValue: function(e) {
return (u.intAddress << 7 | e - 1 & 15).toString(16)
},
@zimmra I pushed a branch that might work for you, haven't had time to test it myself though: main...light-load-state-name
Very cool! I'm hesitant to change my modifications on my active/live system because it's been working well for me, but I'll be able to spin up a second development HA instance and give this a whirl - should be able to sometime this week
My system derives its load numbers differently than yours. (I am running 9.4.6 on a Linux based smart host)
Without modifying the code, the state within Home Assistant was being tracked properly when controlled from Savant, but I had no control over the lights from Home Assistant.
I am not sure if this is due to me being on 9.4.x or if it is just how they do this on Linux based hosts.
My load numbers follow a pattern of 80->100->180->200->280->300->380, and so on
I had to change this function to follow that on my system
https://github.com/thetoothpick/savant-lighting-hacs/blob/fa0df9c63bc4e634d134d9e3b8771fc68a9bfb63/custom_components/savant_lighting/api/light.py#L70-L71
Changed to:
I don't expect you to necessarily adopt this in to your codebase - was more just documenting my findings in case somebody else wants to try this on their system.
I don't think there are enough potential Savant (Lighting)+Home Assistant users out there to warrant your code taking this in to account.