Homeassistat.change_entity (the missed SUPERPOWER service)

I have been thinking a lot about Home Assistant power automating things with all concepts related (entity, automation (trigger/condition/action), scripts, services, etc.) and I reach the best powerfull option to make a lot of things that are really dificult in HA:

The “homeassistat.change_entity” service

With this, you could change things like:

  • state of a entity (i.e. to make one entity sync with another entity, etc.)
  • attributes of a entity (i.e. changing the friendly name)
  • internal parameters (i.e the main is the scan_interval of a sensor). This is really useful and is very demanded around the forum:
    • scan waze-time only when go-to / come-from work (and not every minute ad-infinitum). [Reduce unnecesary servers usage, reduce database HA!!! ] . See too Scheduled polling for Tesla
    • disable bluetooth mi-flora plant scan when playing a film using a2dp bluetooth due to interferences [avoid posible interferences between sensors]

Example:
Call service: homeassistant.change_entity
Data (json): {entity_id: “sensor.waze_time2work”, “scan_interval”: “2 min”}

I understand that change the scan_interval parameter has a huge impact insede HA, but I think that for a really powerful automation system is a MUST_HAVE option.

A way to disable/enable polling would be nice with this too

Could be with negative values:

disable: scan_interval = “-1 seg”
or even more possibilities: negative values execute only one “polling” in specific time, and no more.

I have reached the first one thing:

  1. change the state of a entity (i.e. to make one entity sync with another entity, etc.)

The brief howto is:

  1. Enable python script module including this line @configuration.yaml
    python_script:
  2. Create a set_state.py file in folder ‘config/python_scripts/’

$ nano /homeassistant/.homeassistant/python_scripts/set_state.py

entity_id = data.get('entity_id')
if not entity_id:
    logger.error('No entity_id provided')
state = data.get('state')
if not state:
    logger.error('No state provided')
hass.states.set(entity_id, state)
  1. Now you have a service that can be called in automations. An example of action inside a automation:

     - alias: Securitas_Refresh
      trigger:
      - entity_id: sensor.securitas
        platform: state
      condition: []
      action:
      - service: python_script.set_state
        data_template:
          entity_id: alarm_control_panel.securitas
          state: '{{states.sensor.securitas.state}}'
      - service: others
    

Now, could be great modify the “set_state.py” script to change the attritutes too.

Have you seen this:
https://github.com/home-assistant/home-assistant/pull/17278

Uaaaaaauuuuuuuuuhhhhh…

imagen

So then. There will be a new service
homeassistant/update_entity
that could be called to make a sensor “update” manually.
This could be really great, because you could

Define the sensors in HA with a fixed forever “scan_interval” was really annoying for a good automation system.

Now, I can i.e get 3 sensors waze travel-to-work time scanning one time a day, and execute ‘update_entity’ every minute when I am going to leave home, to see where of the 3 posibles ways are better.

Or i.e. get the result of a shell_command (because it has missed that doenst have any sensor to get the result of the command…). I can create a sensor “never” scaned, and force “update_entity” just after the command was executing, reading the result of the command…
(See Shell_command returned state )