- 积分
- 274
- 金钱
- 263
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
中级会员
- 积分
- 274
- 金钱
- 263
- HASS币
- 0
|
发表于 2024-8-10 21:17:01
|
显示全部楼层
因为松下app难用的空调定时配置,导致我周末不在家空调还开了两天。
今天下午花时间抓包研究了一下,也参考了@omegaojian前辈和台湾版本https://github.com/osk2/panasonic_smart_app的工程实现
如果想工程化这个项目,当前还有几个问题:
1. 密码的加密算法可能是app本地完成的,之后和服务端进行校验,推测每次生成的密文是一致的,但是如果搞不清楚加密算法(安卓app解包逆向可能能拿到),还是得依赖一次抓包,不够优雅。(台湾版本没有这个逻辑,直接传密码过去)
2. device的token推测也是本地生成的,和设备一一对应,不会变,如果不是服务端而是本地生成,同样依赖生成算法,问题和上面一致。(台湾版本也没有这个逻辑,token服务端返回,但是有个app_token没细看是干啥的)
综合以上两个卡点,当前最简单的办法还是手机app登陆后抓一次包,拿到usrId、deviceId、SSID(xtoken)、token这几个参数后,实现剩余步骤的工程化,可以做的功能全面美观一些;或者直接用Command line的switch实现。
如果能找到有松下设备,爱折腾,懂逆向,会开发这几个因素都具备的人,不太容易。
我目前用Command line的switch解决了我的需求,可以做更复杂的空调开关策略了
这是我的配置,适配我当前2024.7版本的语法,自己拿去替换几个关键参数然后放到configuration.yaml里就能用,我的设备是控制松下风管机
```
command_line:
- switch:
name: LivingRoom-AirConditioner
scan_interval: 30
command_on: >
SSID="Axxxxxxxxxxxxxxxxx3"; usrId="5xxxxx0"; deviceId="4xxxxxxxxxF_0xxx_xxxx"; token="0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7";curl 'https://app.psmartcloud.com/App/ACDevSetStatusInfoAW' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'DNT: 1' -H 'Origin: https://app.psmartcloud.com' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1' -H 'X-Requested-With: XMLHttpRequest' -H "xtoken: SSID=$SSID" --data-raw "{\"id\":211,\"usrId\":\"$usrId\",\"deviceId\":\"$deviceId\",\"token\":\"$token\",\"params\":{\"runMode\":3,\"forceRunning\":0,\"runStatus\":1,\"remoteForbidMode\":0,\"remoteMode\":0,\"setTemperature\":52,\"setHumidity\":0,\"windSet\":10,\"exchangeWindSet\":0,\"portraitWindSet\":15,\"orientationWindSet\":13,\"nanoeG\":0,\"nanoe\":0,\"ecoMode\":0,\"muteMode\":0,\"filterReset\":0,\"powerful\":0,\"powerfulMode\":0,\"thermoMode\":0,\"buzzer\":1,\"autoRunMode\":0,\"unusualPresent\":0,\"runForbidden\":0,\"inhaleTemperature\":0,\"outsideTemperature\":0,\"insideHumidity\":0,\"alarmCode\":\"0200\",\"nanoeModule\":0,\"TDWindModule\":0}}" --insecure
command_off: >
SSID="Axxxxxxxxxxxxxxxxx3"; usrId="5xxxxx0"; deviceId="4xxxxxxxxxF_0xxx_xxxx"; token="0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7";curl 'https://app.psmartcloud.com/App/ACDevSetStatusInfoAW' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'DNT: 1' -H 'Origin: https://app.psmartcloud.com' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1' -H 'X-Requested-With: XMLHttpRequest' -H "xtoken: SSID=$SSID" --data-raw "{\"id\":19,\"usrId\":\"$usrId\",\"deviceId\":\"$deviceId\",\"token\":\"$token\",\"params\":{\"runMode\":3,\"forceRunning\":0,\"runStatus\":0,\"remoteForbidMode\":0,\"remoteMode\":0,\"setTemperature\":52,\"setHumidity\":0,\"windSet\":10,\"exchangeWindSet\":0,\"portraitWindSet\":15,\"orientationWindSet\":13,\"nanoeG\":0,\"nanoe\":0,\"ecoMode\":0,\"muteMode\":0,\"filterReset\":0,\"powerful\":0,\"powerfulMode\":0,\"thermoMode\":0,\"buzzer\":1,\"autoRunMode\":0,\"unusualPresent\":0,\"runForbidden\":0,\"inhaleTemperature\":0,\"outsideTemperature\":0,\"insideHumidity\":0,\"alarmCode\":\"0200\",\"nanoeModule\":0,\"TDWindModule\":0}}" --insecure
command_state: >
SSID="Axxxxxxxxxxxxxxxxx3"; usrId="5xxxxx0"; deviceId="4xxxxxxxxxF_0xxx_xxxx"; token="0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7";curl 'https://app.psmartcloud.com/App/ACDevGetStatusInfoAW' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'DNT: 1' -H 'Origin: https://app.psmartcloud.com' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1' -H 'X-Requested-With: XMLHttpRequest' -H "xtoken: SSID=$SSID" --data-raw "{\"id\":217,\"usrId\":\"$usrId\",\"deviceId\":\"$deviceId\",\"token\":\"$token\"}" --insecure
value_template: >
{{value_json['results']['runStatus'] == 1 }}
icon: >
{% if value_json['results']['runStatus'] == 1 %} mdi:air-conditioner
{% else %} mdi:fan-off
{% endif %}
```
多台设备的话复制一下`- switch`和之后的部分,在改一下名字和变量就好
- switch:
name: BedRoom-AirConditioner |
|