Disabling specific sensors when another device is off?

Howdy all.

I have a Tuya smart plug integration and I have a 3D printer connected. I have sensors for the printer setup in my configuration.yaml

Eg sensor.printer_current, printer_filename, printer_timerrmaining etc. These are set to check every 10 minutes.

What I want to do it automate it so when the Tuya plug is off, don’t poll the sensors (then I don’t have to see the constant unable to connect to sensor.printer_xyz in the logs all the time. And of course the opposite behaviour.(I believe I could use the update_entity call when the plug state is “on” to force checks of said sensors, just don’t know how to do the disable.

Does anyone know if/how this achievable?

Thank you

What controls this timing? If it’s an automation., use a condition that the Tuya plug needs to be ON

1 Like

See: How to set a custom scan_interval

1 Like

Another reply to one of my old posts in case anyone else is interested in my solution. (AKA probably me when I go searching for the same issue again in a years time)

I ended up making two automations:

First I check the state of the plug to which my Octoprint Raspberry Pi is connected (you can use anything here).
Then if its off, I know my printer won’t be printing…so I disable all the sensors

alias: Disable Alpha Sensors When Alpha_Pi_Plug is Off
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.alpha_pi_plug
    from:
      - "on"
    to: null
    for:
      hours: 0
      minutes: 5
      seconds: 0
conditions: []
actions:
  - action: homeassistant.disable_entity
    metadata: {}
    data:
      entity_id:
        - camera.alpha_octoprint_camera
        - sensor.alpha_octoprint_current_file
        - sensor.alpha_octoprint_current_file_size
        - sensor.alpha_octoprint_current_state
        - sensor.alpha_octoprint_estimated_finish_time
        - sensor.alpha_octoprint_job_percentage
        - button.alpha_octoprint_pause_job
        - binary_sensor.alpha_octoprint_printing
        - binary_sensor.alpha_octoprint_printing_error
        - button.alpha_octoprint_reboot_system
        - button.alpha_octoprint_restart_octoprint
        - button.alpha_octoprint_resume_job
        - button.alpha_octoprint_shutdown_system
        - sensor.alpha_octoprint_start_time
        - button.alpha_octoprint_stop_job
        - sensor.alpha_printer_plug_voltage
        - sensor.alpha_octoprint_actual_bed_temp
        - number.alpha_octoprint_extruder_temperature
        - sensor.alpha_octoprint_target_bed_temp
        - sensor.alpha_octoprint_target_tool0_temp
        - number.alpha_octoprint_bed_temperature
        - sensor.alpha_octoprint_actual_tool0_temp
        - camera.alpha_mjpeg_cam
mode: single

And Script 2, Same as the first one, but backwards
Turn the sensors back on when the Octoprint Plug is turned on.

alias: Enable Alpha Sensors When Alpha_Pi_Plug is On
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.alpha_pi_plug
    for:
      hours: 0
      minutes: 0
      seconds: 20
    from: null
    to:
      - "on"
conditions: []
actions:
  - action: homeassistant.enable_entity
    metadata: {}
    data:
      entity_id:
        - camera.alpha_octoprint_camera
        - sensor.alpha_octoprint_current_file
        - sensor.alpha_octoprint_current_file_size
        - sensor.alpha_octoprint_current_state
        - sensor.alpha_octoprint_estimated_finish_time
        - sensor.alpha_octoprint_job_percentage
        - button.alpha_octoprint_pause_job
        - binary_sensor.alpha_octoprint_printing
        - binary_sensor.alpha_octoprint_printing_error
        - button.alpha_octoprint_reboot_system
        - button.alpha_octoprint_restart_octoprint
        - button.alpha_octoprint_resume_job
        - button.alpha_octoprint_shutdown_system
        - sensor.alpha_octoprint_start_time
        - button.alpha_octoprint_stop_job
        - number.alpha_octoprint_extruder_temperature
        - number.alpha_octoprint_bed_temperature
        - sensor.alpha_octoprint_actual_bed_temp
        - sensor.alpha_octoprint_actual_tool0_temp
        - sensor.alpha_octoprint_target_bed_temp
        - sensor.alpha_octoprint_target_tool0_temp
        - camera.alpha_mjpeg_cam
mode: single

Hope this helps anyone looking for a similar fix. And Venomouse, if this is you…your memory sucks.