Skip to content

Commit

Permalink
docs(scripts): explain and show examples for binary sensor output
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Jan 4, 2024
1 parent 222c3ab commit 60ef251
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .vscode/ltex.dictionary.en-US.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ABRT
Hass
Fyne
ProcFS
cron
19 changes: 13 additions & 6 deletions docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

Go Hass Agent supports utilising scripts to create sensors. In this way, you can
extend the sensors presented to Home Assistant by the agent. Note that as the
agent is a "mobile app" in Home Assistant, any script sensors will be associated
with the Go Hass Agent device in Home Asssistant.
agent is a mobile app in Home Assistant, any script sensors will be associated
with the Go Hass Agent device in Home Assistant.

Each script run by the agent can create one or more sensors and each script can
run on its own schedule, specified using a Cron-like syntax.
Expand Down Expand Up @@ -41,13 +41,14 @@ Icon](https://pictogrammers.github.io/@mdi/font/2.0.46/) representing the
current state. It can be changed dynamically based on the current state or
remain constant. Format is `mdi:icon_name`.
- `sensor_state`: the current value of the sensor. For numerical states, without
the units. Otherwise a string or bool (for binary sensors).
the units. Otherwise, a *string* or *boolean* (for binary sensors).
- **Note:** for a binary sensor, do not enclose the `true`/`false` in quotes.

The following optional fields can also be specified, which help control the display in Home Assistant.

- `sensor_units`: the units for the state value.
- `sensor_type`: the *type* of sensor. If this is a binary sensor with a boolean
value, set this to *"binary"*. Else, do not set this field.
value, set this to *binary*. Else, do not set this field.
- `sensor_device_class`: a Home Assistant [Device Class](https://developers.home-assistant.io/docs/core/entity/sensor/#available-device-classes)
for the sensor, which will dictate how it will be displayed in Home Assistant.
There are many, pick an appropriate one (see
Expand Down Expand Up @@ -121,6 +122,12 @@ sensor_state = 3
sensor_state_class = 'measurement'
```

For a binary sensor, the output should have `sensor_type` set to “binary” and the `sensor_state` as `true` or `false`
(without quotes). As an example in compressed JSON format:

```json
{"schedule":"@every 10s","sensors":[{"sensor_name":"random 4","sensor_type":"binary","sensor_icon":"mdi:dice-3","sensor_state":false}]}
```

## Schedule

Expand All @@ -137,7 +144,7 @@ Or a pre-defined schedule:
- `@monthly`.
- `@yearly`.

However, more cron-like formats are supported:
However, more cron formats are supported:

- `"30 * * * *"`: every hour on the half hour.
- `"30 3-6,20-23 * * *"`: in the range 3-6am, 8-11pm.
Expand All @@ -147,4 +154,4 @@ However, more cron-like formats are supported:

## Security

Running scripts can be dangerous, especially if the script does not have robust error-handling or whose origin is untrusted or unknown. Go Hass Agent makes no attempt to do any analysis or sanitisation of script output, other than ensuring the output is a [valid supported format](#output-format). As such, ensure you trust and understand what the script does and all possible outputs that the script can produce. Scripts are run by the agent and have the permissions of the user running the agent. Script output is sent to your Home Assistant instance.
Running scripts can be dangerous, especially if the script does not have robust error-handling or whose origin is untrusted or unknown. Go Hass Agent makes no attempt to do any analysis or sanitisation of script output, other than ensuring the output is a [supported format](#output-format). As such, ensure you trust and understand what the script does and all possible outputs that the script can produce. Scripts are run by the agent and have the permissions of the user running the agent. Script output is sent to your Home Assistant instance.

0 comments on commit 60ef251

Please sign in to comment.