直连树莓派的LED(2)
——HA中的shell_command/binary_sensor.command_line/light.template
操作步骤
- 尝试使用shell命令控制LED
- 使用shell_command和light.template构建设备
- 使用binary_sensor.command_line组件反馈灯的状态
参考
- sysfs控制命令
创建GPIO控制文件: echo 17 > /sys/class/gpio/export
删除GPIO控制文件: echo 17 > /sys/class/gpio/unexport
配置输入/输出方向: echo out > /sys/class/gpio/gpio17/direction
输出电压: echo 1 > /sys/class/gpio/gpio17/value
输出零: echo 0 > /sys/class/gpio/gpio17/value
-
配置(
example_15_2_1.yaml
)shell_command: gpio17_init: (echo 17 > /sys/class/gpio/export) && (sleep 1) && (echo out > /sys/class/gpio/gpio17/direction) gpio17_deinit: (echo 17 > /sys/class/gpio/unexport) gpio17_turn_on: (echo 1 > /sys/class/gpio/gpio17/value) gpio17_turn_off: (echo 0 > /sys/class/gpio/gpio17/value)
automation: - alias: create GPIO17 sysfs initial_state: True trigger: - platform: homeassistant event: start action: service: shell_command.gpio17_init - alias: delete GPIO17 sysfs initial_state: True trigger: - platform: homeassistant event: shutdown action: service: shell_command.gpio17_deinit
light: - platform: template lights: gpio17_led_light: friendly_name: GPIO17_LED turn_on: service: shell_command.gpio17_turn_on turn_off: service: shell_command.gpio17_turn_off # value_template: "{{ states.binary_sensor.gpio17_value.state }}"
#binary_sensor: # - platform: command_line # name: gpio17_value # command: cat /sys/class/gpio/gpio17/value # payload_on: 1 # payload_off: 0 # scan_interval: 1
-
shell_command组件配置
https://www.home-assistant.io/integrations/shell_command
- light.template组件配置
https://www.home-assistant.io/integrations/light.template
- binary_sensor.command_line组件配置