Run a script inside a scene

I recently bought an iPhone and discovered the Home Assistant widget where I can easily run Scene. I have some tapo c200 cameras with the privacy function that I can call as a service.

I wanted to create a script that disable the privacy mode on cameras and start recording when a movement is detected. The script works fine but I can’t run it from inside a scene.

Creating a scene I can’t call the service to disable the privacy mode so why it’s not possible to run a script inside a scene? I think it’s something we should be able to do.

EDIT: a workaround I found is to run an automation from a scene even if I prefer running a script from a scene

Pretty sure that isn’t possible either. Can you show your scene?

Scenes convert specified states into service calls to set those states. So if you are setting the automation on or off, you are enabling / disabling it. Not triggering it.

If you want the sort of functionality described in your post title, don’t use a scene. Use a script. You just have to use service calls yourself to set the states you want.

If the scene sets light 1 at 10% and light 2 at 20% and the volume of media player at 50%, then all those are conditions in an automation.
All you need is a trigger and that could be either of those entities.

So possible for sure.

No it isn’t. Vincenzo is setting the state of an automation in a scene, probably with the assumption that this runs the automation. It does not.

It’s possible to replace the scene with an automation, but that is not what they have done. And a better fit would be replacing the scene with a script.

It’s working. On the scene I have just my automation as device. Then in the automation as trigger I have a state for

domain: scene
service: turn_on
service_data:
  entity_id: scene.camera_recording_on

then the actions I want

That is a very convoluted way of going about it.

Just replace the scene with a script.

I can’t because what I want to reach is having the scene on my iphone HA widget so I must use scene. I wanted to call a script from a scene but it’s not possible so I’m calling an automation instead.

This is my code:

SCENE

- id: '1619801047175'
  name: Camera ON
  entities:
    automation.camera_on:
      last_triggered: '2021-10-18T07:23:05.476255+00:00'
      mode: queued
      current: 4
      max: 5
      id: '1634541742343'
      friendly_name: Camera ON
      state: 'on'

AUTOMATION

- id: '1634541742343'
  alias: Camera ON
  description: ''
  trigger:
    platform: event
    event_type: call_service
    event_data:
      domain: scene
      service: turn_on
      service_data:
        entity_id: scene.camera_recording_on
  action:
  - service: tapo_control.set_privacy_mode
    target:
      entity_id:
      - camera.tapo_camera_bedroom_hd
      - camera.tapo_camera_bedroom_sd
      - camera.tapo_camera_living_room_hd
      - camera.tapo_camera_living_room_sd
      - camera.tapo_camera_office_hd
      - camera.tapo_camera_office_sd
    data:
      privacy_mode: 'off'

Maybe cleaner:

  1. Create an input_boolean
  2. Trigger an automation based on the state of the boolean
  3. Add the boolean to the scene

Or a just template switch. Switches can be used in Homekit.

switch:
  - platform: template
    switches:
      privacy_mode:
        friendly_name: 'Privacy Mode'
        value_template: >
          {{ is_state_attr('camera.tapo_camera_bedroom_hd', 'privacy_mode', 'on') and
            is_state_attr('camera.tapo_camera_bedroom_sd', 'privacy_mode', 'on') and
            is_state_attr('camera.tapo_camera_living_room_hd', 'privacy_mode', 'on') and
            is_state_attr('camera.tapo_camera_living_room_sd', 'privacy_mode', 'on') and
            is_state_attr('camera.tapo_camera_office_hd', 'privacy_mode', 'on') and
            is_state_attr('camera.tapo_camera_office_sd', 'privacy_mode', 'on') }}
        turn_on:
          - service: tapo_control.set_privacy_mode
            target:
              entity_id:
              - camera.tapo_camera_bedroom_hd
              - camera.tapo_camera_bedroom_sd
              - camera.tapo_camera_living_room_hd
              - camera.tapo_camera_living_room_sd
              - camera.tapo_camera_office_hd
              - camera.tapo_camera_office_sd
            data:
              privacy_mode: 'on'
        turn_off:
          - service: tapo_control.set_privacy_mode
            target:
              entity_id:
              - camera.tapo_camera_bedroom_hd
              - camera.tapo_camera_bedroom_sd
              - camera.tapo_camera_living_room_hd
              - camera.tapo_camera_living_room_sd
              - camera.tapo_camera_office_hd
              - camera.tapo_camera_office_sd
            data:
              privacy_mode: 'off'
1 Like

Indeed. Added bonus: You get a live status of the global “privacy” mode.

1 Like

I am assuming privacy_mode is an attribute of the camera though. If it isn’t it all comes undone.

It’s working. On the automation I’ve also other actions like recording when cameras detect movement, sent notification to my smartphone and possibly I can add more. Can I put those in the template?

I don’t know, I’m thinking it’s just easier to do it with automation that triggers when I run the scene.

You can add more actions to the switch turn on and off action lists, but they will only run when you turn the switch on or off.

I have been wondering about this and was going to make a post on it, but seems approppriate to just comment here. WHAT IS THE POINT OF SCENES!?!?!? It seems to me that between automations and scripts, you would never need to create a scene? What are any use case scenarios where you would use scene vs. automation/script? Thanks all!

  1. They’re easy to create for people who don’t understand services. You just specify the state you want and the scene works out which service to call.

  2. They can be used to capture the state of entities “on the fly”, and restore that saved state later.

1 Like

ahhhh ya, #2 is a great point. I actually use that exact function to return my lights to previous state after they flash (when my 4 yo escapes his room). Thanks for the reply!