How to make ANY Entity-based sensor updatable only upon request (standard command_line
integration as an example)
If you want to stop HA from updating state of your Entity-based sensor (anything that accepts scan_interval
configuration variable) so you can update it when you need by calling homeassistant.update_entity
, it's possible using monkey patching and custom integrations.
Note: you should understand that you're playing with HA's internals and your code would break if something changes in HA (class renamed, file structure changed etc). Keep it in mind when designing your setup around this functionality.
You will need to:
- install the custom integration (
manual_command_line
in this example) by copying this folder into your<HA configfolder>/custom_components/
- add the custom integration's domain
manual_command_line:
to yourconfiguration.yaml
(as shown here) - declare your sensor as usual
That's it.
To use it with another standard (let's say sensor
) integration (template sensor) you need to:
- rename the custom's integration folder to something unique in HA integrations (
my_silent_sensor
) - in manifest.json set
domain
to that value (my_silent_sensor
) - in manifest.json change
after_dependencies
to your standard integration's domain (sensor
) - in
__init__.py
changeDOMAIN
as per step 2 - in
__init__.py
changeimport homeassistant.components.command_line.sensor
toimport homeassistant.components.template.sensor
- in
configuration.yaml
changemanual_command_line:
as per step 2 (my_silent_sensor:
) - declare your standard sensor as usual
sensor:
- platform: template
- save changes and restart Home Assistant
If you need to do it with more than one standard integration:
- repeat step 3 adding comma-separated remaining integrations' domains ("[sensor, binary_sensor]")
- add remaining
import
s similar to the original one - make sure all
as xxx
have uniquexxx
- use these
xxx
instead ofsensor
create as manysensor.CommandSensor.should_poll = should_poll
as necessary. Note that you'll need to change class name (CommandSensor
) to a class name that your standard integration is based on.