Turning on (enable) a sensor from a script

Hi all, been looking for a way to do this for weeks now, tried many things. I have a solution with NodeRed, but I would love to accomplish this with HA only.

Goal: To enable a sensor from an automation

Ex: I have live sensors (pH, oxygen, EC) from Tasmota, sendinf MQTT values. Those sensors will be in 3 different liquids depending on some valve’s status (on/off). So, I’m trying to “enable” a sensor from an automation, only when a valve is open and after a few minutes.

So:

  1. Open valve 1
  2. wait 2min
  3. Enable those live sensors data to copy to new sensors ex:
  • Live sensor: pH
  • New sensor : pH_Valve1
  1. wait 2min
  2. disable the copy of live sensors to those _valve1 sensors.

In other words, I will have 3 sets of new sensors _ValveX, receiving values only when I enable them from an automation.

I know how to create a new sensor from an existing state. That’s OK, but how to control the “copy” of live data to this new sensor from an automation?

In NodeRed, I can copy MQTT message from the live sensor to a new sensor based on a switch state, but again, I’m trying to do all this in HA.

Hope it’s clear enough!

Thanks, Simon