The ``nextion`` binary sensor platform supports the many switched components in the Nextion as well as integer variables (>0 == true). It can be a component or variable in the Nextion display.
-**name** (**Required**, string): The name of the sensor.
-**nextion_id** (*Optional*, :ref:`config-id`): The ID of the Nextion display.
-**component_name** (*Optional*, string): The name of the Nextion component.
-**variable_name** (*Optional*, string): The name of the Nextion variable. Any value over ``0`` is considered to be **on**
-**page_id** (*Optional*, string): The ID of the page the component is on. Use ``0`` for the default page.
-**component_id** (*Optional*, string): The ID (the number, not name!) of the component to track.
-**update_interval** (*Optional*, :ref:`config-time`): The duration to update the sensor. If using a :ref:`nextion_custom_binary_sensor_protocol` this should not be used
-**background_color** (*Optional*, :ref:`config-color`): The background color
-**foreground_color** (*Optional*, :ref:`config-color`): The foreground color
this native event **page_id** and **component_id** are required. No :ref:`nextion_custom_binary_sensor_protocol` is required. If **page_id** and **component_id** are set then the component will only react to touch events from the Nextion. Setting **component_name** will allow setting options like foreground color.
``background_color(s)`` , ``foreground_color(s)`` and ``visible`` do not retain their state on page change. :ref:`Binary Sensor Settings <nextion_binary_sensor_settings>`.
A :ref:`Nextion Sensor <nextion_sensor>` with a custom protocol sending the current page can be used to execute the API call :ref:`Update Components By Prefix <update_components_by_prefix>` to update all the components for that page
See :ref:`nextion_binary_sensor_how_things_update` for additional information
Globals
*******
The Nextion does not retain data on Nextion page changes. Additionally if a page is changed and the **nextion_component_name** does not exist on that page then
nothing will be updated. To get around this the Nextion components can be changed to have a vscope of ``global``. If this is set then the **nextion_component_name**
should be prefixed with the page name (page0/page1).
*Example*
``nextion_component_name: page0.r0``
.._nextion_binary_sensor_lambda_calls:
Lambda Calls
************
From :ref:`lambdas <config-lambda>`, you can call several methods to access some
more advanced functions (see the full :apiref:`nextion/binary_sensor/nextion_binarysensor.h` for more info).
.._nextion_binary_sensor_set_state:
-``set_state(bool value, bool publish, bool send_to_nextion)``: Set the state to **value**. Publish the new state to HASS. Send_to_Nextion is to publish the state to the Nextion.
.._nextion_binary_sensor_update:
-``update()``: Poll from the Nextion
.._nextion_binary_sensor_settings:
-``set_background_color(Color color)``: Sets the background color to **Color**
-``set_background_pressed_color(Color color)``: Sets the background color to **Color**
-``set_foreground_color(Color color)``: Sets the background color to **Color**
-``set_foreground_pressed_color(Color color)``: Sets the background color to **Color**
-``set_visible(bool visible)`` : Sets visible or not. If set to false, no updates will be sent to the component
.._nextion_binary_sensor_how_things_update:
How things Update
-----------------
A Nextion component with an integer value (.val) or Nextion variable will be automatically polled if **update_interval** is set.
To have the Nextion send the data you can use the :ref:`nextion_custom_binary_sensor_protocol` for this. Add the :ref:`nextion_custom_binary_sensor_protocol` to the
component or function you want to trigger the send. Typically this is in *Touch Press Event* but some components, like a slider, should have it
set in the *Touch Release Event* to capture all the changes. Since this is a custom protocol it can be sent from anywhere (timers/functions/components)
No updates will be sent to the Nextion if it is sleeping. Once it wakes the components will be updated. If a component is invisible , :code:`visible(false)` , then it won't update until it is set to be visible.