home-assistant.io/source/_components/sensor.simulated.markdown
Benedict Aas 798cc33839 add relative time option to simulated sensors (#5223)
This is the documentation for the change outlined below.

By default simulated sensors are relative to when they're activated,
instead we change this default to a new toggleable option,
'relative_to_epoch', and instead they become 'absolute', or relative
to 1970-01-01 00:00:00.
2018-06-14 14:07:16 -04:00

3.1 KiB

layout, title, description, date, sidebar, comments, sharing, footer, logo, ha_category, ha_iot_class, ha_release
layout title description date sidebar comments sharing footer logo ha_category ha_iot_class ha_release
page Simulated sensor Component for simulating a numerical sensor. 2018-02-20 08:00 true false true true home-assistant.png Sensor Local Polling 0.65

The simulated sensor platform provides a simulated sensor that generates a time-varying signal V(t) given by the function:

V(t) = M + A sin((2 pi (t - t_0) / w) + P) + N(s)

where:

  • M = the mean value of the sensor
  • A = the amplitude of the periodic contribution
  • t = the time when a value is generated
  • t_0 = the time when the sensor is started
  • w = the time period in seconds for a single complete cycle of the periodic contribution
  • P = the phase offset to add to the periodic contribution, in units of degrees
  • N(s) = the random Gaussian noise with spread s

The output will be limited to 3 decimals.

{% linkable_title Configuration %}

To add a simulated sensor to your installation, add the following to your configuration.yaml file:

sensor:
  - platform: simulated

{% configuration %} name: description: The name of the sensor. required: false default: simulated type: string unit: description: The unit to apply. required: false default: value type: string amplitude: description: The amplitude of periodic contribution. required: false default: 1 type: float mean: description: The mean level of the sensor. required: false default: 0 type: float period: description: The time in seconds for one complete oscillation of the periodic contribution. required: false default: 0 type: seconds phase: description: The phase offset (in degrees) to apply to the periodic component. required: false default: 0 type: float seed: description: The seed value for the random noise component. required: false default: 999 type: int spread: description: The spread is the range of the randomly distributed values about their mean. This is sometimes referred to as the Full Width at Half Maximum (FWHM) of the random distribution. required: false default: None type: float relative_to_epoch: description: Whether to simulate from epoch time (00:00:00, 1970-01-01), or relative to when the sensor was started. required: false default: true type: boolean {% endconfiguration %}

{% linkable_title Example %}

To give an example of simulating real world data, a simulated relative humidity sensor (in %) can be added using the following configuration:

sensor:
  - platform: simulated
    name: 'simulated relative humidity'
    unit: '%'
    amplitude: 0 # Turns off the periodic contribution
    mean: 50
    spread: 10
    seed: 999
    relative_to_epoch: false