项目作者: akasma74

项目描述 :
Alternative to HA's Min/Max sensor
高级语言: Python
项目地址: git://github.com/akasma74/homeassistant-multisource-sensor.git


homeassistant: multisource sensor

Intro

This sensor is based on Min/Max sensor,
which is very useful to compute one value based on a number of related values.
The main problem with the Min/Max sensor was that its state is always numerical as it keeps the
last numerical (i.e not unknown/unavailable) state of its entities according to the docs.
Therefore its state won’t be unknown even if all of its entities’ states are unknown and one needs
to take their own measures to react to such situation as per this discussion.
This can be done using automations and additional entities, but it won’t be as flexible as
a custom component.
On the other hand, there is always a risk when using custom component as if something changes in
a way Home Assistant handles them, you’re in troubles.
So you’ve been warned.

Description

Definition of the sensor is similar to Min/Max sensor.
It inherits its sources’ icon and unit_of_measurement (which defaults to ERR if they mismatch across sources).


sensors
(list) (Required)
Configurations for individual sensors.


name
(string) (Required)
Name of sensor.


type
(string) (Optional)
The type of sensor (same as for Min/Max sensor). Supported values are min, last.

  1. _Default value:_
  2. `last`


sources
(list) (Required)
List of sensors to combine.


selectable_sources
(boolean) (Optional)
If true, each source will be considered only if a corresponding selector is on.

  1. _Default value:_
  2. false


selectors
(list) (Optional)
List of input_booleans.
If present, number of items should be equal to sources‘ one.
Otherwise you should have configured input_booleans so
for each source_x there is an input_boolean.source_x_selected.


round_digits
(number) (Optional)
Number of digits to round the value of sensor.
If omitted, state of the sensor will be a copy of the source’s state (i.e no change).

  1. _Default value:_
  2. -1


friendly_name
(string) (Optional)
Human friendly name of sensor.

Installation

Copy custom_components/multisource folder into your <HA config>/custom_components/ folder.
You may need to restart Home Assistant.

Use

  1. Simple case - one physical sensor and two receivers (RFLink and OMG Pilight).
    Each of them has its own sensor in Home Assistant. Wwe combine them to get the last arrived reading:
    ```yaml

    these sensors reflect appropriate protocol’s values

    and behave like ‘last’ filter but change to ‘unknown’ if all of the entity_id are unknown

  • platform: multisource
    sensors:
    ground_floor_reception_reliable_temperature:

    1. friendly_name: !secret ground_floor_reception_name
    2. sources:
    3. - sensor.pilight_ground_floor_reception_temperature
    4. - sensor.rflink_ground_floor_reception_temperature

    ground_floor_lounge_reliable_temperature:

    1. friendly_name: !secret ground_floor_lounge_name
    2. sources:
    3. - sensor.pilight_ground_floor_lounge_temperature
    4. - sensor.rflink_ground_floor_lounge_temperature

    ```

  1. Using these sensors as sources, we can now create a combined sensor whose state represents
    the minimal value of its sources. We also use round_digits to set resulting precision:
    ```yaml
  • platform: multisource
    sensors:
    composite_temperature:
    1. friendly_name: composite temperature
    2. type: min
    3. round_digits: 1
    ```
  1. Any multisource sensor can be configured to enable/disable its sources (which might be
    useful to exclude some of them either manually or by an automation)
    ```yaml
  • platform: multisource
    sensors:
    composite_temperature:
    1. friendly_name: composite temperature
    2. type: min
    3. round_digits: 1
    4. selectable_sources: true
    5. sources:
    6. - sensor.ground_floor_reception_reliable_temperature
    7. - sensor.ground_floor_lounge_reliable_temperature
    oryaml
  • platform: multisource
    sensors:
    ground_floor_reception_reliable_temperature:
    1. friendly_name: !secret ground_floor_reception_name
    2. selectable_sources: true
    3. sources:
    4. - sensor.pilight_ground_floor_reception_temperature
    5. - sensor.rflink_ground_floor_reception_temperature
    6. selectors:
    7. - input_boolean.pilight_ground_floor_reception
    8. - input_boolean.rflink_ground_floor_reception
    ```