Custom attributes for unavailable devices doesn't appear

Hi everyone!

For scripting purposes, I need to add some extra attributes to some sensors. After adding them, I noticed that if the actual device is unavailable or it’s restore state set to true, custom attributes are not set.

Here’s a bunch of attributes I’ve added:

# Moode
media_player.audio_2:
  friendly_name: Ampli Bureau
  icon: mdi:speaker
  device_class: speaker
  plug: "switch.plug_9"
  delay_after_plug_on: 0
  wait_for_trigger_status: off
  turn_media_on_off: false
  delay_after_media_on: 0
  set_volume: true
  wait_for_device_after_play: true

# Caméra Salon 
media_player.camera_1_yh_media_player:
  plug: "switch.plug_2"
  delay_after_plug_on: 30
  wait_for_trigger_status: idle
  turn_media_on_off: false
  delay_after_media_on: 0
  set_volume: false
  wait_for_device_after_play: false
...
switch.plug_9:
  media_player: "media_player.audio_2"

switch.plug_2:
  media_player: "media_player.camera_1_yh_media_player"

Once HA or customization reloaded, I don’t see them, like for media_player.camera_1_yh_media_player:

But for some reason, even if media_player.audio_2 is unavailable, I can see them, which is not the case for media_player.camera_1_yh_media_player.

But I believe it has something to do with restored: true but I haven’t been able to find relevant information in the doc or the forum.

I need these information as cameras are linked to plugs, which by default are not up.

Can someone tell how to have these information even if the device is unavailable? Or I need to ass an extra parameter to set the restore attribute to false?

Thanks!

After many tests, I’m still struggling with this.

My use case for this is that I have a generic script for play TTS on all my media players (MusicCast, MPD and Yi-Hack). All these devices are plugged on smart plugs and all these devices behave differently and need specific instructions before being able to play TTS.

Thanks!

Nobody? I am totally out of ideas

Do you recall what you did to cause the media_player to get the restored: true attribute?

Thanks for your response @123.

Clearly not, I’ve never touch anything like that in my configuration.

The only difference I see between these 2 entities are their integration: the 1st one (audio_2) comes from MPD (configured via configuration.yaml) and doesn’t have any UI configuration while the other one comes from Yi Hack.

I also note a pattern for this restored: true: I have a Musicast integration (through the UI) and the behavior is similar. No custom attributes while it’s unavailable.

Still no success but I was wondering if it’s possible to add custom attributes using a service? Or something else?

As of now, the only workaround I found is to switch on plugs to get attributes populated for the entities I need. Would be great if someone had a better idea :slight_smile:

BTW @123 , can you tell what is the purpose of "restored":true?

I’ve been able to make an Restful API call to add a custom attribute but weirdly, it doesn’t work for full text-based integration like MPD while it works for Musciast:

  • Musiccast (webUI): even if the integration is set to reload itself to test if the device is up (mine is connected to a smart plug), the custom attribute survives
  • MPD (text-based): the custom attribute lives for a short moment and then disappear, probably after the integration reloads

I believe it has nothing to do with webUI/text-based integration but more with some obscure internal mechanism that I will be happy to understand so that I can use the custom attributes feature without using workarounds.

Thanks!