配置放到 homeassistant/configuration.yaml 文件中, 重启后在 ui 里找不到开关,设备和实体里都没有,也没有日志报错
docker 中安装的
Home Assistant
Core 2024.12.5
Frontend 20241127.8
switch:
- platform: command_line
switches:
my_switch:
command_on: "'"
command_off: "curl -X GET 'http://192.168.10.57:6095/controller?action=keyevent&keycode=power'"
command_state: "curl -s --max-time 10 'http://192.168.10.57:6095/request?action=isalive'"
value_template: "{{ value != '' }}" # 如果返回内容,则表示开关开启
availability_template: >
{% if not value or value == '' %}
false # 如果没有返回内容,表示不可用
{% else %}
true # 如果有返回内容,表示可用
{% endif %}
scan_interval: 3
name: "xiaomi_tv"
icon: "mdi:power"
unique_id: "xiaomi_tv_http"
1
withoutxx OP 试下了这么写,貌似可以
``` command_line: - sensor: name: CPU Temperature command: "cat /sys/class/thermal/thermal_zone0/temp" unit_of_measurement: "°C" value_template: '{{ value | multiply(0.001) }}' unique_id: "cpu_temperature" - switch: name: TV Power command_on: "" command_off: "curl -s 'http://192.168.10.57:6095/controller?action=keyevent&keycode=power' || echo ''" command_state: "curl -s --max-time 1 'http://192.168.10.57:6095/request?action=isalive' || echo ''" value_template: "{{ value != '' }}" scan_interval: 5 unique_id: "xiaomi_tv_power" ``` |