Send receiver state to espeasy/esphome

I have a Denon receiver hidden in a cabinet. I want to reflect it’s current state (power on/off, input source) to an external LCD powered by esphome or espeasy via an http call. The Denon receiver is instantiated as a media_player using the Denon AVR network receivers integration. I’ve tried many different ways to extract the state of the Denon and everything fails. Here is my non-working entry from automations.yaml (excuse any formatting issues, this is my first post)

- id: '1661665167001'            
  alias: Reflect_Fam_Denon_Status                     
  trigger:                                            
  - platform: device                                  
    type: changed_states                              
    entity_id: media_player.denon_fam_room
    domain: media_player
  condition: []        
  action:                                  
      - rest_command:
           - url: "http://192.168.xx.xx/endpt?state={ states(media_player.denon_fam_room) }&source={ states(media_player.denon_fam_room.source) }"

I’m trying to get the on/off state from: { states(media_player.denon_fam_room) } and the source input state from: { states(media_player.denon_fam_room.source) }. I’m also not certain my trigger is correct.

As you are looking for a state change, I’d use a state trigger:

I think your action does not work this way. I think you have to define the rest_command as described here:

and then call that service in your automation (and pass your variables to it). Described here:

And one side note: Even if you could use an url template at this place, I think the names of the entities should be marked as strings.

Thanks for helping. Whenever I try to reference the state of the Denon using a construct such as: {{ media_player.denon_fam_room }} or {{ media_player.denon_fam_room.source }}, I get this error: UndefinedError: ‘media_player’ is undefined

OK, after a bunch of trial and error I got something that works well. For triggering I can check the before and after state of an entity and an attribute:

 trigger:                                                      
    platform: state                                             
    entity_id: media_player.denon_fam_room          
  condition:                                                    
   - condition: template                                        
     value_template: >                                          
       {{ trigger.to_state.state != trigger.from_state.state and
          trigger.from_state.attributes.source !=
          trigger.to_state.attributes.source }}           
  action:                                  
  - service: rest_command.send_denon_state

For the rest command, I used the following:

rest_command:                                                              
    send_denon_state:                                                        
         url: "http://192.168.xx.xx/cgi/endpt?state={{ states('media_player.denon_fam_room') }}&source={{ state_attr('media_player.denon_fam_room', 'source') }}"