thetoothpick / savant-lighting-hacs

MIT License
1 stars 0 forks source link

Import works, but no control or state #1

Closed zimmra closed 3 months ago

zimmra commented 6 months ago

Nice to see someone else trying to integrate their Savant switches in to Home Assistant.

I got this installed and setup - it correctly imports my loads from Savant and differentiates switches vs dimmers, but I have no control of them and they all report off, and do not update their state.

I have debug logging enabled for savant_lighting but don't see anything beyond the intial line when it is discovered.

Is there something that needs to be enabled on the Savant side? Is your Savant system host a Linux based host or a macOS based host ('Smart' or 'Pro'), and what version is yours running?

thetoothpick commented 6 months ago

Hey! Likewise, glad you found your way here. This is a quick side-project I threw together to get my lights integrated, so apologies for the lack of debug logging and whatnot.

My host is running 10.3.0:582-cprd1. It's a point release behind my Android app version (10.4), so my system might be behind the latest. It's running on MacOS (Pro).

The main lighting app runs on port 80 on my host, and includes a full control interface based on websockets. The websocket server runs on a different port (8480). That's hardcoded in this integration, so if you're getting any light information at all, that part is at least the same.

I would assume (without any further information) that your version might be ahead of (or behind) mine, and that they've updated their protocol. There are separate websocket messages for getting information about devices vs. getting their state, so maybe the state-loading messages changed. According to the initial protocol handshake, my system is using protocol version 0.1.

I'll try to get some proper logging checked in, as well the python scripts I used to test my integration. In the meantime, if you can load the web app on port 80, and you're comfortable in the Chrome web tools, try to examine the websocket connection on the network tab. The first message should include the protocol version

Thanks for checking this out!

zimmra commented 6 months ago

I'm on a Smart Host, 9.4.x, so mine is Linux-based (I think 9.4.2, but my Mac Mini is on the fritz so I don't have access to SDE/SAM currently.)

Also appears to be protocol version 0.1 and same ports

Websocket request info:

Request Headers:

GET ws://192.168.2.50:8480/ HTTP/1.1
Host: 192.168.2.50:8480
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: http://192.168.2.50
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Sec-GPC: 1
Sec-WebSocket-Key: redacted
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Protocol: savant_protocol

Response Headers:

HTTP/1.1 101 Switching Protocols
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Accept: redacted
Sec-WebSocket-Protocol: savant_protocol

Initial WS Message:

{"messages":[{"protocolVersion":"0.1","device":{"name":"windows","version":null,"app":"Savant Smart Lighting (build.rev:7.0 Dev)","ip":"192.168.2.50","model":"unknown"}}],"URI":"session/devicePresent"}

Example 'Turn On' Message:

{"messages":[{"state":"load.300","value":"100%"}],"URI":"state/set"}

Example 'Turn Off' Message:

{"messages":[{"state":"load.300","value":"0%"}],"URI":"state/set"}
zimmra commented 6 months ago

I can provide any other specific messages too, if helpful.

Here us the messages seen when monitoring status of load (when controlling my load Kitchen Overhead from within Savant, not from 'Lighting WebGUI')

(The Hass* scenes can be ignored, they are through my 'hacky' integration of using the Emulated Roku integration within Home Assistant to get the two systems to communicate)

Kitchen Overhead On:

{ "messages": [
{ "state": "rtc-out", "value": "RLGLV,Kitchen Overhead Scene,7,100,1" },
{ "state": "rtc-out", "value": "RLGLV,Whole Home On,9,100,0" },
{ "state": "rtc-out", "value": "RLGLV,Whole Home Off,10,0,0" },
{ "state": "rtc-out", "value": "RLGLV,Movie Time,11,100,0" },
{ "state": "rtc-out", "value": "RLGLV,HassKitchenOn,15,100,1" },
{ "state": "rtc-out", "value": "RLGLV,HassKitchenOff,16,0,1" },
{ "state": "rtc-out", "value": "RLGLV,Room:Kitchen,34,100,1" },
{ "state": "rtc-out", "value": "RLGLV,RoomMid:Kitchen,35,100,1" },
{ "state": "rtc-out", "value": "RLGLV,RoomLow:Kitchen,36,100,1" }
], "URI": "state/update" }

Kitchen Overhead Off:

{ "messages": [
{ "state": "rtc-out", "value": "RLGLV,Kitchen Overhead Scene,7,0,0" },
{ "state": "rtc-out", "value": "RLGLV,Whole Home On,9,75,0" },
{ "state": "rtc-out", "value": "RLGLV,Whole Home Off,10,0,0" },
{ "state": "rtc-out", "value": "RLGLV,Movie Time,11,100,0" },
{ "state": "rtc-out", "value": "RLGLV,HassKitchenOn,15,0,0" },
{ "state": "rtc-out", "value": "RLGLV,HassKitchenOff,16,0,0" },
{ "state": "rtc-out", "value": "RLGLV,Room:Kitchen,34,50,1" },
{ "state": "rtc-out", "value": "RLGLV,RoomMid:Kitchen,35,50,1" },
{ "state": "rtc-out", "value": "RLGLV,RoomLow:Kitchen,36,50,1" }
], "URI": "state/update" }
thetoothpick commented 6 months ago

Interesting. When you click on a particular light in the web UI, do you see any messages with a URI like state/module/xxx/get? This is what my client uses to get the state of a certain device. Home Assistant will periodically tell the client to update the lights' states, and it sends that message to savant for each light. If you can capture those types of messages (in and out), I should be able to figure out if there's a difference.

The messages you posted are only for scenes, but it seems like one can also send a message like this to receive module updates on the state/update URI:

{messages: [{state: "module"}], URI: "state/register"}

which subscribes to messages like this:

{ "messages": [
{ "state": "module.029", "value": "100,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1" }
], "URI": "state/update" }

I've already pushed an updated client with updated debug logging, I'll also try to add support for that state/update message tonight. Give the updated version a shot when you can!

zimmra commented 6 months ago

Sorry I still haven't had the time to re-mess with this - the more I thought about it, it is almost surely because of my Savant setup. I have the 'lighting' disabled on the lighting device buttons, but 'control' enabled

e.g.: image image

This is due to the combination of most of my loads having 'smart' bulbs (so I am not wanting to control the load output of the dimmer/switch, just capture the button press) and my hacky 'integration' between HASS <-> Savant via emulated rokus

Because of my use-case of not wanting to control the actual load output of the dimmers/switches, I expect to have to modify what you have done.

Should have time this coming week to really dive in to it.

zimmra commented 3 months ago

This is more of an issue with my implementation than an issue with code, will open a new GH issue for code-specific issue(s)