From 437a19218f586d1fa03fa016dcd609c951bd62c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Sat, 18 Mar 2023 22:39:41 +0100 Subject: [PATCH] Document how to return 'no value' from a lambda filter (#2761) * Document how to filter out values in a lambda filter * Fix the code example --- components/sensor/index.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/sensor/index.rst b/components/sensor/index.rst index 42dd1b993..6ee6f5ded 100644 --- a/components/sensor/index.rst +++ b/components/sensor/index.rst @@ -493,6 +493,16 @@ the result of the lambda is used as the output (use ``return``). Make sure to add ``.0`` to all values in the lambda, otherwise divisions of integers will result in integers (not floating point values). +To prevent values from being published, return ``{}``: + +.. code-block:: yaml + + filters: + - lambda: !lambda |- + if (x < 10) return {}; + return x-10; + + Example: Converting Celsius to Fahrenheit -----------------------------------------