Calling a service in Python and giving a target entity_id

Please, how do I translate this YAML example into Python?

 -   service: media_player.volume_set
     entity_id: media_player.downstairs
     data:
       volume_level: '1.0'

The HA documentation basically gives this example:

hass.services.call("light", "turn_on", data, False)

So far my Python translation is:

hass.services.call("media_player", "volume_set", data, False)

I don’t think the entity_id belongs into data, as it is not part of data in the YAML example. Where does it go?

thx

1 Like

Not sure, but what I’d do is search the core repo for examples of this being called.

1 Like

Thanks for answers.

I tried to set the entity_id into data now. It does surprisingly work.

Hope it’s not due to a side effect, like using the previous device by default, when no target it given in the appropriate place.

Is this still working? I’m continuously getting an error saying

Error executing script: not a valid value for dictionary value @ data['entity_id']