From bc137041d8c33778efbce53a606637a8cab66f87 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Thu, 14 Feb 2019 14:39:09 -0500 Subject: [PATCH] Added templates to Bayesian sensor (#8408) * Added templates to Bayesian sensor * change quotes * more changes * Added raw/endraw tags --- .../binary_sensor.bayesian.markdown | 65 +++++++++++++------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/source/_components/binary_sensor.bayesian.markdown b/source/_components/binary_sensor.bayesian.markdown index 6154fbaa1f2..81424f7d666 100644 --- a/source/_components/binary_sensor.bayesian.markdown +++ b/source/_components/binary_sensor.bayesian.markdown @@ -57,10 +57,21 @@ observations: required: true type: list keys: - entity_id: - description: Name of the entity to monitor. + platform: + description: > + The supported platforms are `state`, `numeric_state`, and `template`. + They are modeled after their corresponding triggers for automations, + requiring `to_state` (for `state`), `below` and/or `above` (for `numeric_state`) and `value_template` (for `template`). required: true type: string + entity_id: + description: Name of the entity to monitor. + required: true (for `state` and `numeric_state`) + type: string + value_template: + description: Defines the template to be used. + required: true (for `template`) + type: template prob_given_true: description: The probability of the observation occurring, given the event is `true`. required: true @@ -70,17 +81,10 @@ observations: required: false type: float default: "`1 - prob_given_true` if `prob_given_false` is not set" - platform: - description: > - The only supported observation platforms are `state` and `numeric_state`, - which are modeled after their corresponding triggers for automations, - requiring `below` and/or `above` instead of `to_state`. - required: true - type: string to_state: description: The target state. - required: true - type: string + required: true (for `state`) + type: string {% endconfiguration %} ## {% linkable_title Full examples %} @@ -95,23 +99,23 @@ binary_sensor: prior: 0.25 probability_threshold: 0.95 observations: - - entity_id: 'sensor.living_room_motion' + - platform: 'state' + entity_id: 'sensor.living_room_motion' prob_given_true: 0.4 prob_given_false: 0.2 - platform: 'state' to_state: 'off' - - entity_id: 'sensor.basement_motion' + - platform: 'state' + entity_id: 'sensor.basement_motion' prob_given_true: 0.5 prob_given_false: 0.4 - platform: 'state' to_state: 'off' - - entity_id: 'sensor.bedroom_motion' + - platform: 'state' + entity_id: 'sensor.bedroom_motion' prob_given_true: 0.5 - platform: 'state' to_state: 'on' - - entity_id: 'sun.sun' + - platform: 'state' + entity_id: 'sun.sun' prob_given_true: 0.7 - platform: 'state' to_state: 'below_horizon' ``` @@ -126,8 +130,27 @@ binary_sensor: prior: 0.2 probability_threshold: 0.9 observations: - - entity_id: 'sensor.outside_air_temperature_fahrenheit' + - platform: 'numeric_state' + entity_id: 'sensor.outside_air_temperature_fahrenheit' prob_given_true: 0.95 - platform: 'numeric_state' below: 50 ``` + +Finally, here's an example for `template` observation platform, +as seen in the configuration it requires `value_template` and does not use `entity_id`. + +{% raw %} +```yaml +# Example configuration.yaml entry +binary_sensor: + name: 'Paulus Home' + platform: 'bayesian' + prior: 0.5 + probability_threshold: 0.9 + observations: + - platform: template + value_template: > + {{is_state('device_tracker.paulus','not_home') and ((as_timestamp(now()) - as_timestamp(states.device_tracker.paulus.last_changed)) > 300)}} + prob_given_true: 0.95 +``` +{% endraw %}