本帖最后由 flamestsui 于 2023-3-7 09:09 编辑
结果,我自己搞定了。我发现有个坑的是,curl访问是localhost和127.0.0.1就失败。我把接受文件换成域名就行了。passwall.yaml
sensor:
- platform: command_line
name: checkPassWall
command: "python3 /config/script/checkPassWall.py"
value_template: "{{ value }}"
switch:
- platform: command_line
switches:
checkpasswall:
command_on: "python3 /config/script/openPassWall.py"
command_off: "python3 /config/script/closePassWall.py"
command_state: "python3 /config/script/checkPassWall.py"
value_template: '{{ value == "on" }}'
friendly_name: openWRT PassWall
unique_id: checkpasswall
icon_template: >-
{% if is_state('sensor.checkPassWall', 'on') %}
mdi:router-wireless
{% else %}
mdi:router-wireless-off
{% endif %}
checkPassWall.py
import openWRTs
if __name__ == '__main__':
openWrt = openWRTs.openWRT("http://192.168.88.2", "root", "lieyanxh14.")
openWrt.login()
print(openWrt.checkPassWall())
openPassWall.py
import openWRTs
if __name__ == '__main__':
openWrt = openWRTs.openWRT("http://192.168.88.2", "root", "lieyanxh14.")
openWrt.login()
openWrt.openPassWall()
if openWrt.isChanges():
openWrt.submit()
openWrt.confrim()
|