Move Command Line to integration key (#27343)

This commit is contained in:
G Johansson 2023-05-29 21:19:43 +02:00 committed by GitHub
parent a73986b3e3
commit 57414b73c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,17 +21,6 @@ ha_integration_type: integration
The `command_line` offers functionality that issues specific commands to get data or to control a device. The `command_line` offers functionality that issues specific commands to get data or to control a device.
## Binary sensor
To use your Command binary sensor in your installation, add the following to your `configuration.yaml` file:
```yaml
# Example configuration.yaml entry
binary_sensor:
- platform: command_line
command: "cat /proc/sys/net/ipv4/ip_forward"
```
<div class='note'> <div class='note'>
It's highly recommended to enclose the command in single quotes `'` as it ensures all characters can be used in the command and reduces the risk of unintentional escaping. To include a single quote in a command enclosed in single quotes, double it: `''`. It's highly recommended to enclose the command in single quotes `'` as it ensures all characters can be used in the command and reduces the risk of unintentional escaping. To include a single quote in a command enclosed in single quotes, double it: `''`.
@ -39,76 +28,56 @@ It's highly recommended to enclose the command in single quotes `'` as it ensure
</div> </div>
{% configuration %} {% configuration %}
command: command_line:
description: The action to take to get the value. description: The platforms to use for you command_line integration.
required: true
type: string
command_timeout:
description: Defines number of seconds for command timeout.
required: false
type: integer
default: 15
device_class:
description: Sets the [class of the device](/integrations/binary_sensor/), changing the device state and icon that is displayed on the frontend.
required: false
type: string
name:
description: Let you overwrite the name of the device.
required: false
type: string
default: "*name* from the device"
payload_on:
description: The payload that represents enabled state.
required: false
type: string
default: 'ON'
unique_id:
description: An ID that uniquely identifies this binary sensor. Set this to a unique value to allow customization through the UI.
required: false
type: string
payload_off:
description: The payload that represents disabled state.
required: false
type: string
default: 'OFF'
scan_interval:
description: Defines number of seconds for polling interval.
required: false
type: integer
default: 60
value_template:
description: Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
required: false
type: string
{% endconfiguration %}
## Cover
A `command_line`cover platform that issues specific commands when it is moved up, down and stopped. It allows anyone to integrate any type of cover into Home Assistant that can be controlled from the command line.
To enable a command line cover in your installation, add the following to your `configuration.yaml` file:
```yaml
# Example configuration.yaml entry
cover:
- platform: command_line
covers:
garage_door:
command_open: move_command up garage
command_close: move_command down garage
command_stop: move_command stop garage
```
{% configuration %}
covers:
description: The array that contains all command line covers.
required: true required: true
type: list type: list
keys: keys:
identifier: binary_sensor:
description: Name of the command line cover as slug. Multiple entries are possible. description: Binary sensor platform.
required: true required: false
type: list type: map
keys:
command:
description: The action to take to get the value.
required: true
type: string
command_timeout:
description: Defines number of seconds for command timeout.
required: false
type: integer
default: 15
device_class:
description: Sets the [class of the device](/integrations/binary_sensor/), changing the device state and icon that is displayed on the frontend.
required: false
type: string
name:
description: Let you overwrite the name of the device.
required: false
type: string
default: "*name* from the device"
payload_on:
description: The payload that represents enabled state.
required: false
type: string
default: 'ON'
unique_id:
description: An ID that uniquely identifies this binary sensor. Set this to a unique value to allow customization through the UI.
required: false
type: string
payload_off:
description: The payload that represents disabled state.
required: false
type: string
default: 'OFF'
value_template:
description: Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
required: false
type: string
cover:
description: Cover platform.
required: false
type: map
keys: keys:
command_close: command_close:
description: The action to close the cover. description: The action to close the cover.
@ -134,15 +103,10 @@ covers:
required: false required: false
type: integer type: integer
default: 15 default: 15
friendly_name: name:
description: The name used to display the cover in the frontend. description: The name used to display the cover in the frontend.
required: false required: true
type: string type: string
scan_interval:
description: Defines number of seconds for polling interval.
required: false
type: integer
default: 60
unique_id: unique_id:
description: An ID that uniquely identifies this cover. Set this to a unique value to allow customization through the UI. description: An ID that uniquely identifies this cover. Set this to a unique value to allow customization through the UI.
required: false required: false
@ -150,119 +114,63 @@ covers:
value_template: value_template:
description: if specified, `command_state` will ignore the result code of the command but the template evaluating will indicate the position of the cover. For example, if your `command_state` returns a string "open", using `value_template` as in the example configuration above will allow you to translate that into the valid state `100`. description: if specified, `command_state` will ignore the result code of the command but the template evaluating will indicate the position of the cover. For example, if your `command_state` returns a string "open", using `value_template` as in the example configuration above will allow you to translate that into the valid state `100`.
required: false required: false
default: "'{% raw %}{{ value }}{% endraw%}'"
type: template type: template
{% endconfiguration %} notify:
description: Notify platform.
## Notify required: false
type: map
The `command_line` platform allows you to use external tools for notifications from Home Assistant. The message will be passed in as STDIN. keys:
name:
To enable those notifications in your installation, add the following to your `configuration.yaml` file: description: Setting the optional parameter `name` allows multiple notifiers to be created. The notifier will bind to the service `notify.NOTIFIER_NAME`.
required: false
```yaml default: notify
# Example configuration.yaml entry type: string
notify: command:
- name: NOTIFIER_NAME description: The action to take.
platform: command_line required: true
command: "espeak -vmb/mb-us1" type: string
``` command_timeout:
description: Defines number of seconds for command timeout.
{% configuration %} required: false
name: type: integer
description: Setting the optional parameter `name` allows multiple notifiers to be created. The notifier will bind to the service `notify.NOTIFIER_NAME`. default: 15
required: false sensor:
default: notify description: Sensor platform.
type: string required: false
command: type: map
description: The action to take. keys:
required: true command:
type: string description: The action to take to get the value.
command_timeout: required: true
description: Defines number of seconds for command timeout. type: string
required: false command_timeout:
type: integer description: Defines number of seconds for command timeout
default: 15 required: false
{% endconfiguration %} type: integer
default: 15
To use notifications, please see the [getting started with automation page](/getting-started/automation/). json_attributes:
description: Defines a list of keys to extract values from a JSON dictionary result and then set as sensor attributes.
## Sensor required: false
type: [string, list]
To enable it, add the following lines to your `configuration.yaml`: name:
description: Name of the command sensor.
```yaml required: false
# Example configuration.yaml entry type: string
sensor: unique_id:
- platform: command_line description: An ID that uniquely identifies this sensor. Set this to a unique value to allow customization through the UI.
command: SENSOR_COMMAND required: false
``` type: string
unit_of_measurement:
{% configuration %} description: Defines the unit of measurement of the sensor, if any.
command: required: false
description: The action to take to get the value. type: string
required: true value_template:
type: string description: "Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload."
command_timeout: required: false
description: Defines number of seconds for command timeout type: string
required: false switch:
type: integer description: Switch platform.
default: 15 required: false
json_attributes:
description: Defines a list of keys to extract values from a JSON dictionary result and then set as sensor attributes.
required: false
type: [string, list]
name:
description: Name of the command sensor.
required: false
type: string
unique_id:
description: An ID that uniquely identifies this sensor. Set this to a unique value to allow customization through the UI.
required: false
type: string
scan_interval:
description: Defines number of seconds for polling interval.
required: false
type: integer
default: 60
unit_of_measurement:
description: Defines the unit of measurement of the sensor, if any.
required: false
type: string
value_template:
description: "Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload."
required: false
type: string
{% endconfiguration %}
## Switch
The `command_line` switch platform issues specific commands when it is turned on
and off. This might very well become our most powerful platform as it allows
anyone to integrate any type of switch into Home Assistant that can be
controlled from the command line, including calling other scripts!
To enable it, add the following lines to your `configuration.yaml`:
```yaml
# Example configuration.yaml entry
switch:
- platform: command_line
switches:
kitchen_light:
command_on: switch_command on kitchen
command_off: switch_command off kitchen
```
{% configuration %}
switches:
description: The array that contains all command switches.
required: true
type: map
keys:
identifier:
description: Name of the command switch as slug. Multiple entries are possible.
required: true
type: map type: map
keys: keys:
command_on: command_on:
@ -282,19 +190,14 @@ switches:
required: false required: false
type: integer type: integer
default: 15 default: 15
friendly_name: name:
description: The name used to display the switch in the frontend. description: The name used to display the switch in the frontend.
required: false required: true
type: string type: string
icon_template: icon_template:
description: Defines a template for the icon of the entity. description: Defines a template for the icon of the entity.
required: false required: false
type: template type: template
scan_interval:
description: Defines number of seconds for polling interval.
required: false
type: integer
default: 60
unique_id: unique_id:
description: An ID that uniquely identifies this switch. Set this to a unique value to allow customization through the UI. description: An ID that uniquely identifies this switch. Set this to a unique value to allow customization through the UI.
required: false required: false
@ -305,19 +208,96 @@ switches:
type: string type: string
{% endconfiguration %} {% endconfiguration %}
A note on `friendly_name`: ## Binary sensor
When set, the `friendly_name` had been previously used for API calls and backend To use your Command binary sensor in your installation, add the following to your `configuration.yaml` file:
configuration instead of the `object_id` ("identifier"), but
[this behavior is changing](https://github.com/home-assistant/home-assistant/pull/4343) {% raw %}
to make the `friendly_name` for display purposes only. This allows users to set ```yaml
an `identifier` that emphasizes uniqueness and predictability for API and configuration # Example configuration.yaml entry
purposes but have a prettier `friendly_name` still show up in the UI. As an command_line:
additional benefit, if a user wanted to change the `friendly_name` / display - binary_sensor:
name (e.g., from "Kitchen Lightswitch" to "Kitchen Switch" or command: "cat /proc/sys/net/ipv4/ip_forward"
"Living Room Light", or remove the `friendly_name` altogether), they could ```
do so without needing to change existing automations or API calls. {% endraw%}
See aREST device below for an example.
## Cover
A `command_line`cover platform that issues specific commands when it is moved up, down and stopped. It allows anyone to integrate any type of cover into Home Assistant that can be controlled from the command line.
To enable a command line cover in your installation, add the following to your `configuration.yaml` file:
{% raw %}
```yaml
# Example configuration.yaml entry
command_line:
- cover:
command_open: move_command up garage
command_close: move_command down garage
command_stop: move_command stop garage
name: Garage
```
{% endraw%}
## Notify
The `command_line` platform allows you to use external tools for notifications from Home Assistant. The message will be passed in as STDIN.
To enable those notifications in your installation, add the following to your `configuration.yaml` file:
{% raw %}
```yaml
# Example configuration.yaml entry
command_line:
- notify:
command: "espeak -vmb/mb-us1"
```
{% endraw%}
To use notifications, please see the [getting started with automation page](/getting-started/automation/).
## Sensor
To enable it, add the following lines to your `configuration.yaml`:
{% raw %}
```yaml
# Example configuration.yaml entry
command_line:
- sensor:
command: SENSOR_COMMAND
```
{% endraw%}
## Switch
The `command_line` switch platform issues specific commands when it is turned on
and off. This might very well become our most powerful platform as it allows
anyone to integrate any type of switch into Home Assistant that can be
controlled from the command line, including calling other scripts!
To enable it, add the following lines to your `configuration.yaml`:
{% raw %}
```yaml
# Example configuration.yaml entry
command_line:
- switch:
name: Kitchen Light
command_on: switch_command on kitchen
command_off: switch_command off kitchen
```
{% endraw%}
<div class='note'>
A note on `name` for `cover` and `switch`:
The use of `friendly_name` and `object_id` has been deprecated and the slugified `name` will also be used as identifier.
Use `unique_id` to enable changing the name from the UI if required to use `name` as identifier object as required.
</div>
## Execution ## Execution
@ -339,42 +319,48 @@ In this section you find some real-life examples of how to use the command_line
Check the state of an [SickRage](https://github.com/sickragetv/sickrage) instance. Check the state of an [SickRage](https://github.com/sickragetv/sickrage) instance.
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
binary_sensor: command_line:
- platform: command_line - binary_sensor:
command: 'netstat -na | find "33322" | find /c "LISTENING" > nul && (echo "Running") || (echo "Not running")' command: 'netstat -na | find "33322" | find /c "LISTENING" > nul && (echo "Running") || (echo "Not running")'
name: "sickragerunning" name: "sickragerunning"
device_class: moving device_class: moving
payload_on: "Running" payload_on: "Running"
payload_off: "Not running" payload_off: "Not running"
``` ```
{% endraw%}
### Check RasPlex ### Check RasPlex
Check if [RasPlex](https://github.com/RasPlex/RasPlex) is `online`. Check if [RasPlex](https://github.com/RasPlex/RasPlex) is `online`.
{% raw %}
```yaml ```yaml
binary_sensor: command_line:
- platform: command_line - binary_sensor:
command: 'ping -c 1 rasplex.local | grep "1 received" | wc -l' command: 'ping -c 1 rasplex.local | grep "1 received" | wc -l'
name: "is_rasplex_online" name: "is_rasplex_online"
device_class: connectivity device_class: connectivity
payload_on: 1 payload_on: 1
payload_off: 0 payload_off: 0
``` ```
{% endraw%}
An alternative solution could look like this: An alternative solution could look like this:
{% raw %}
```yaml ```yaml
binary_sensor: command_line:
- platform: command_line - binary_sensor:
name: Printer name: Printer
command: 'ping -W 1 -c 1 192.168.1.10 > /dev/null 2>&1 && echo success || echo fail' command: 'ping -W 1 -c 1 192.168.1.10 > /dev/null 2>&1 && echo success || echo fail'
device_class: connectivity device_class: connectivity
payload_on: "success" payload_on: "success"
payload_off: "fail" payload_off: "fail"
``` ```
{% endraw%}
Consider to use the [ping sensor](/integrations/ping#binary-sensor) as an alternative to the samples above. Consider to use the [ping sensor](/integrations/ping#binary-sensor) as an alternative to the samples above.
@ -382,6 +368,7 @@ Consider to use the [ping sensor](/integrations/ping#binary-sensor) as an altern
The services running is listed in `/etc/systemd/system` and can be checked with the `systemctl` command: The services running is listed in `/etc/systemd/system` and can be checked with the `systemctl` command:
{% raw %}
```bash ```bash
$ systemctl is-active home-assistant@rock64.service $ systemctl is-active home-assistant@rock64.service
active active
@ -389,38 +376,40 @@ $ sudo service home-assistant@rock64.service stop
$ systemctl is-active home-assistant@rock64.service $ systemctl is-active home-assistant@rock64.service
inactive inactive
``` ```
{% endraw%}
A binary command line sensor can check this: A binary command line sensor can check this:
{% raw %}
```yaml ```yaml
binary_sensor: command_line:
- platform: command_line - binary_sensor:
command: '/bin/systemctl is-active home-assistant@rock64.service' command: '/bin/systemctl is-active home-assistant@rock64.service'
payload_on: "active" payload_on: "active"
payload_off: "inactive" payload_off: "inactive"
``` ```
{% endraw%}
## Example cover platform ## Example cover platform
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
cover: command_line:
- platform: command_line - cover:
covers: name: Garage door
garage_door: command_open: move_command up garage
command_open: move_command up garage command_close: move_command down garage
command_close: move_command down garage command_stop: move_command stop garage
command_stop: move_command stop garage command_state: state_command garage
command_state: state_command garage value_template: >
value_template: > {% if value == 'open' %}
{% if value == 'open' %} 100
100 {% elif value == 'closed' %}
{% elif value == 'closed' %} 0
0 {% endif %}
{% endif %}
``` ```
{% endraw%}
## Examples sensor platform ## Examples sensor platform
@ -431,34 +420,35 @@ In this section you find some real-life examples of how to use this sensor.
Thanks to the [`proc`](https://en.wikipedia.org/wiki/Procfs) file system, various details about a system can be retrieved. Here the CPU temperature is of interest. Add something similar to your `configuration.yaml` file: Thanks to the [`proc`](https://en.wikipedia.org/wiki/Procfs) file system, various details about a system can be retrieved. Here the CPU temperature is of interest. Add something similar to your `configuration.yaml` file:
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
sensor: command_line:
- platform: command_line - sensor:
name: CPU Temperature name: CPU Temperature
command: "cat /sys/class/thermal/thermal_zone0/temp" command: "cat /sys/class/thermal/thermal_zone0/temp"
# If errors occur, make sure configuration file is encoded as UTF-8 # If errors occur, make sure configuration file is encoded as UTF-8
unit_of_measurement: "°C" unit_of_measurement: "°C"
value_template: "{{ value | multiply(0.001) | round(1) }}" value_template: "{{ value | multiply(0.001) | round(1) }}"
``` ```
{% endraw%}
{% endraw %}
### Monitoring failed login attempts on Home Assistant ### Monitoring failed login attempts on Home Assistant
If you'd like to know how many failed login attempts are made to Home Assistant, add the following to your `configuration.yaml` file: If you'd like to know how many failed login attempts are made to Home Assistant, add the following to your `configuration.yaml` file:
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
sensor: command_line:
- platform: command_line - sensor:
name: badlogin name: Badlogin
command: "grep -c 'Login attempt' /home/hass/.homeassistant/home-assistant.log" command: "grep -c 'Login attempt' /home/hass/.homeassistant/home-assistant.log"
``` ```
{% endraw%}
Make sure to configure the [Logger integration](/integrations/logger) to monitor the [HTTP integration](/integrations/http/) at least the `warning` level. Make sure to configure the [Logger integration](/integrations/logger) to monitor the [HTTP integration](/integrations/http/) at least the `warning` level.
{% raw %}
```yaml ```yaml
# Example working logger settings that works # Example working logger settings that works
logger: logger:
@ -466,28 +456,33 @@ logger:
logs: logs:
homeassistant.components.http: warning homeassistant.components.http: warning
``` ```
{% endraw%}
### Details about the upstream Home Assistant release ### Details about the upstream Home Assistant release
You can see directly in the frontend (**Developer tools** -> **About**) what release of Home Assistant you are running. The Home Assistant releases are available on the [Python Package Index](https://pypi.python.org/pypi). This makes it possible to get the current release. You can see directly in the frontend (**Developer tools** -> **About**) what release of Home Assistant you are running. The Home Assistant releases are available on the [Python Package Index](https://pypi.python.org/pypi). This makes it possible to get the current release.
{% raw %}
```yaml ```yaml
sensor: command_line:
- platform: command_line - sensor:
command: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])" command: python3 -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"
name: HA release name: HA release
``` ```
{% endraw%}
### Read value out of a remote text file ### Read value out of a remote text file
If you own devices which are storing values in text files which are accessible over HTTP then you can use the same approach as shown in the previous section. Instead of looking at the JSON response we directly grab the sensor's value. If you own devices which are storing values in text files which are accessible over HTTP then you can use the same approach as shown in the previous section. Instead of looking at the JSON response we directly grab the sensor's value.
{% raw %}
```yaml ```yaml
sensor: command_line:
- platform: command_line - sensor:
command: python3 -c "import requests; print(requests.get('http://remote-host/sensor_data.txt').text)" command: python3 -c "import requests; print(requests.get('http://remote-host/sensor_data.txt').text)"
name: File value name: File value
``` ```
{% endraw%}
### Use an external script ### Use an external script
@ -495,12 +490,15 @@ The example is doing the same as the [aREST sensor](/integrations/arest#sensor)
The one-line script to retrieve a value is shown below. Of course it would be possible to use this directly in the `configuration.yaml` file but need extra care about the quotation marks. The one-line script to retrieve a value is shown below. Of course it would be possible to use this directly in the `configuration.yaml` file but need extra care about the quotation marks.
{% raw %}
```bash ```bash
python3 -c "import requests; print(requests.get('http://10.0.0.48/analog/2').json()['return_value'])" python3 -c "import requests; print(requests.get('http://10.0.0.48/analog/2').json()['return_value'])"
``` ```
{% endraw%}
The script (saved as `arest-value.py`) that is used looks like the example below. The script (saved as `arest-value.py`) that is used looks like the example below.
{% raw %}
```python ```python
#!/usr/bin/python3 #!/usr/bin/python3
from requests import get from requests import get
@ -508,53 +506,52 @@ from requests import get
response = get("http://10.0.0.48/analog/2") response = get("http://10.0.0.48/analog/2")
print(response.json()["return_value"]) print(response.json()["return_value"])
``` ```
{% endraw%}
To use the script you need to add something like the following to your `configuration.yaml` file. To use the script you need to add something like the following to your `configuration.yaml` file.
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
sensor: command_line:
- platform: command_line - sensor:
name: Brightness name: Brightness
command: "python3 /path/to/script/arest-value.py" command: "python3 /path/to/script/arest-value.py"
``` ```
{% endraw%}
### Usage of templating in `command:` ### Usage of templating in `command:`
[Templates](/docs/configuration/templating/) are supported in the `command` configuration variable. This could be used if you want to include the state of a specific sensor as an argument to your external script. [Templates](/docs/configuration/templating/) are supported in the `command` configuration variable. This could be used if you want to include the state of a specific sensor as an argument to your external script.
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
sensor: command_line:
- platform: command_line - sensor:
name: wind direction name: Wind direction
command: "sh /home/pi/.homeassistant/scripts/wind_direction.sh {{ states('sensor.wind_direction') }}" command: "sh /home/pi/.homeassistant/scripts/wind_direction.sh {{ states('sensor.wind_direction') }}"
unit_of_measurement: "Direction" unit_of_measurement: "Direction"
``` ```
{% endraw%}
{% endraw %}
### Usage of JSON attributes in command output ### Usage of JSON attributes in command output
The example shows how you can retrieve multiple values with one sensor (where the additional values are attributes) by using `value_json` and `json_attributes`. The example shows how you can retrieve multiple values with one sensor (where the additional values are attributes) by using `value_json` and `json_attributes`.
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
sensor: command_line:
- platform: command_line - sensor:
name: JSON time name: JSON time
json_attributes: json_attributes:
- date - date
- milliseconds_since_epoch - milliseconds_since_epoch
command: "python3 /home/pi/.homeassistant/scripts/datetime.py" command: "python3 /home/pi/.homeassistant/scripts/datetime.py"
value_template: "{{ value_json.time }}" value_template: "{{ value_json.time }}"
``` ```
{% endraw%}
{% endraw %}
## Example switch platform ## Example switch platform
@ -563,28 +560,23 @@ sensor:
This example demonstrates how to use template to change the icon as its state changes. This icon is referencing its own state. This example demonstrates how to use template to change the icon as its state changes. This icon is referencing its own state.
{% raw %} {% raw %}
```yaml ```yaml
switch: command_line:
- platform: command_line - switch:
switches: name: Driveway outside sensor
command_on: >
driveway_sensor_motion: curl -X PUT -d '{"on":true}' "http://ip_address/api/sensors/27/config/"
friendly_name: Driveway outside sensor command_off: >
command_on: > curl -X PUT -d '{"on":false}' "http://ip_address/api/sensors/27/config/"
curl -X PUT -d '{"on":true}' "http://ip_address/api/sensors/27/config/" command_state: curl http://ip_address/api/sensors/27/
command_off: > value_template: >
curl -X PUT -d '{"on":false}' "http://ip_address/api/sensors/27/config/" {{value_json.config.on}}
command_state: curl http://ip_address/api/sensors/27/ icon_template: >
value_template: > {% if value_json.config.on == true %} mdi:toggle-switch
{{value_json.config.on}} {% else %} mdi:toggle-switch-off
icon_template: > {% endif %}
{% if value_json.config.on == true %} mdi:toggle-switch
{% else %} mdi:toggle-switch-off
{% endif %}
``` ```
{% endraw%}
{% endraw %}
### aREST device ### aREST device
@ -594,21 +586,17 @@ The command line tool [`curl`](https://curl.haxx.se/) is used to toggle a pin
which is controllable through REST. which is controllable through REST.
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
switch: command_line:
- platform: command_line - switch:
switches: command_on: "/usr/bin/curl -X GET http://192.168.1.10/digital/4/1"
arest_pin_four: command_off: "/usr/bin/curl -X GET http://192.168.1.10/digital/4/0"
command_on: "/usr/bin/curl -X GET http://192.168.1.10/digital/4/1" command_state: "/usr/bin/curl -X GET http://192.168.1.10/digital/4"
command_off: "/usr/bin/curl -X GET http://192.168.1.10/digital/4/0" value_template: '{{ value == "1" }}'
command_state: "/usr/bin/curl -X GET http://192.168.1.10/digital/4" name: Kitchen Lightswitch
value_template: '{{ value == "1" }}'
friendly_name: Kitchen Lightswitch
``` ```
{% endraw%}
{% endraw %}
Given this example, in the UI one would see the `friendly_name` of Given this example, in the UI one would see the `friendly_name` of
"Kitchen Light". However, the `identifier` is `arest_pin_four`, making the "Kitchen Light". However, the `identifier` is `arest_pin_four`, making the
@ -623,29 +611,31 @@ This switch will shutdown your system that is hosting Home Assistant.
This switch will shutdown your host immediately, there will be no confirmation. This switch will shutdown your host immediately, there will be no confirmation.
</div> </div>
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
switch: command_line:
- platform: command_line - switch:
switches: name: Home Assistant System Shutdown
home_assistant_system_shutdown: command_off: "/usr/sbin/poweroff"
command_off: "/usr/sbin/poweroff"
``` ```
{% endraw%}
### Control your VLC player ### Control your VLC player
This switch will control a local VLC media player This switch will control a local VLC media player
([Source](https://community.home-assistant.io/t/vlc-player/106)). ([Source](https://community.home-assistant.io/t/vlc-player/106)).
{% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
switch: command_line:
- platform: command_line - switch:
switches: name: VLC
vlc: command_on: "cvlc 1.mp3 vlc://quit &"
command_on: "cvlc 1.mp3 vlc://quit &" command_off: "pkill vlc"
command_off: "pkill vlc"
``` ```
{% endraw%}
### Control Foscam Motion Sensor ### Control Foscam Motion Sensor
@ -655,20 +645,17 @@ This switch supports statecmd,
which checks the current state of motion detection. which checks the current state of motion detection.
{% raw %} {% raw %}
```yaml ```yaml
# Example configuration.yaml entry # Example configuration.yaml entry
switch: command_line:
- platform: command_line - switch:
switches: name: Foscam Motion
foscam_motion: command_on: 'curl -k "https://ipaddress:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=admin&pwd=password"'
command_on: 'curl -k "https://ipaddress:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=admin&pwd=password"' command_off: 'curl -k "https://ipaddress:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=admin&pwd=password"'
command_off: 'curl -k "https://ipaddress:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=admin&pwd=password"' command_state: 'curl -k --silent "https://ipaddress:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=admin&pwd=password" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"'
command_state: 'curl -k --silent "https://ipaddress:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=admin&pwd=password" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"' value_template: '{{ value == "1" }}'
value_template: '{{ value == "1" }}'
``` ```
{% endraw%}
{% endraw %}
- Replace admin and password with an "Admin" privileged Foscam user - Replace admin and password with an "Admin" privileged Foscam user
- Replace ipaddress with the local IP address of your Foscam - Replace ipaddress with the local IP address of your Foscam