Custom component - AirMusic radio

I’ve made my first custom_component:

https://github.com/DominikWrobel/airmusic

Tested with:
Oakcastle IR100
Majority Pembroke
Ferguson i300

Should work with:
Dabman i450
Lenco DIR150BK
Majority Kings Internet DAB+ Radio
Conrad’s renkforce IR 1
Kruger&Matz KM0816
Sharp DR-I470

And any other internet radio that uses the android or iOS app AirMusic.

This is my first time with python and coding :wink: so if there are any issues please let me know. Have fun using this!

Now on version 1.2!

What works:

  • Power status and power control: on, off, standby.
  • Loads all sources from Internet Radio favorites.
  • Information about current radio program.
  • Volume regulation (mute, set, step)
  • Change radio channel (Selecting from source list)
  • Current radio channel and current event
  • Supports authentication and multiple receivers
  • Self INIT when setting up the integration
  • Station logos and album art
  • Unique ID
  • Setup via GUI
  • :next_track_button: mapped to next favorite station

Known limitations:

  • Only internet radio control, this integration will work properly only when radio is in Internet Radio mode.
  • Radio / album logo and station info may take up to 10 seconds to update, had to limit requests to radio to limit the chance of radio freezing.

Screenshots:

1
album

If you like my work you can support me via:

Great! thank you for your effort. I will start my testing with my Ferguson i300 as soon as possible.

1 Like

I was able to install de component and add it to the UI. but:

  1. I need to have my Ferguson i300 ON when restarting my HA server.

  2. The Radio entity does not have a unique ID doe to the fact it is installed trough configuration.yaml and so i have no way to configure it.
    Error message for reference:
    This entity (‘media_player.radio’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

  3. connection very unstable and can’t retrieve what is being reproduced or control the device in a consistent manner.

Thank you Again

OK, thx for the info,

  1. My two radios had to be off :rofl: will check that in the documentation
  2. Will be added in the future
  3. Are you using any other way of controling the radio via internet? When using the integration and airmusic app at the same time the radio may hang, also if using some other way of getting info from the radio (like node-red) it will couse problems.

If you have any errors in the log please paste them.

v0.4 released:

  • Station logos now work!
  • Some code cleanup and should be much more stable
  • Remember this integration only works when the radio is in internet radio mode.

v0.4a released:

  • Added unique ID

Updated to V0.6 - Amazing work Dominik congratulations.

  1. Removed and Readded for 0.6 still could only get the device if the radio was on on boot of HA server.

  2. Confirmed as working.

  3. Tried with and without airmusic app. Not using node-red. Even without App Still a lot of difficulty in the integration to retrieve the radio status. And most of the time it is switched (Off- when it is on) and when I press again i can see briefly the controls and the radio station icon before the radio is turned off.

  4. What I did to work around this: just press very quick the on/off bottom on the integration and can have control there.

5.Still when i change station Radio logo is not updated.

  1. Pause, Fast forward and Backward work erratically once even changed to FM radio. other times this 3 buttons get replaced by a single play button.

Once again congratulations on the great work. and just ask for any test i can do from my end.

There is a problem with right control if current radio station is not sending info about station_info or song, I am trying to get around this :wink:

Could you type into your brower http://ip of radio/playinfo when it is on and when off? Paste the result in here.

You should see something like this:

<result>
<vol>0</vol>
<mute>0</mute>
<status>Odtwarzanie </status>
<sid>6</sid>
<stream_format>MP3 /128 Kbps</stream_format>
<logo_img>http://192.168.0.248:8080/playlogo.jpg</logo_img>
<station_info/>
<song>Moje Kilimandżaro</song>
<artist>LADY PANK</artist>
</result>

Also you can try to send me info from IP/list?id=75&start=1&count=20 and IP/init Do this when the radio is on and set in internet radio mode

If you are getting 401 Unatharized we will need to get this info via NodeRed, I can show you how.

Thank you for your help

/init

"<result>
<id>1</id>
<version>h10520170105h</version>
<lang>pt</lang>
<wifi_set_url>http://192.168.78.1/scan_wifi</wifi_set_url>
<ptver>20160526</ptver>
<hotkey_fav>1</hotkey_fav>
<push_talk>1</push_talk>
<leave_msg>1</leave_msg>
<leave_msg_ios>1</leave_msg_ios>
<M7_SUPPORT>0</M7_SUPPORT>
<SMS_SUPPORT>0</SMS_SUPPORT>
<SWUpdate>NO</SWUpdate>
</result>"

/list?id=75&start=1&count=20

<menu>
<item_total>7</item_total>
<item_return>7</item_return>
<item>
<id>75_0</id>
<status>file</status>
<name>Rádio Malaga</name>
</item>
<item>
<id>75_1</id>
<status>file</status>
<name>Smooth</name>
</item>
<item>
<id>75_2</id>
<status>file</status>
<name>Swiss Jazz</name>
</item>
<item>
<id>75_3</id>
<status>file</status>
<name>POPinternacional</name>
</item>
<item>
<id>75_4</id>
<status>file</status>
<name>Taïwan Radio</name>
</item>
<item>
<id>75_5</id>
<status>file</status>
<name>Pacífico</name>
</item>
<item>
<id>75_6</id>
<status>file</status>
<name>Antena Rio de Janeiro FM 103.7</name>
</item>
</menu>

/playinfo With radio off:

<result>FAIL</result>

/playinfo With radio stating to buffer:

<result>
<vol>6</vol>
<mute>0</mute>
<status>A Ligar ...</status>
<sid>1</sid>
</result>

/playinfo With radio Streaming:

<result>
<vol>6</vol>
<mute>0</mute>
<status>A Reproduzir </status>
<sid>6</sid>
<logo_img>http://192.168.1.23:8080/playlogo.jpg</logo_img>
<stream_format>MP3 /64 Kbps</stream_format>
<station_info> </station_info>
<song>BUSY (FOR ME)</song>
<artist>AUREA</artist>
</result>

Looks like mine, next time try formatting the message better, using (```) to quote the copied message.

Try version 0.7 - but the integration works only if the radio is in internet mode status, it will not work if using FM radio.

You can also try using my remote: https://github.com/DominikWrobel/airmusic/tree/main/remote

Sorry for the message formatting I was in a rush to post because i wanted to do it before leaving for work (fixed now).

Updated to v0.8:

  • Instance can’t collect radio on-off status correctly. (still need to use the quick on-off to do the testing)
  • Now there is no drop down menu for selection of the station anymore.
  • FFW and REW button now works to change stations.
  • If volume is increased or decreased the station logo and data gets update in the instance.

Any idea why /init reports for “wifi_set_url>http://192.168.78.1/scan_wifi” ?

About the remote still need to learn how to add it correctly to my Configuration.yaml

thank you for the great work

Ok, making some progress :wink:

If there is no drop down menu it means the integration did not load correctly and did not fetch the list of radio station, for now you will have to restart HA to get it to work. I am looking into this and will try to fix it in the future.

I have released version 0.9 it has alot of code optimalizaton and should make everything work a little bit better. The main problem is that if you send too much requests to the radio it will freeze, that is why I limited requests, but it should not slow down info update in HA. Also added time stamp to the image so that it would not get cached in HA or the browser.

Any idea why /init reports for “wifi_set_url>http://192.168.78.1/scan_wifi” ?

Mine shows the same IP, don’t worry about it.

For the configuration.yaml, just paste the shell_command code below anything you have:

vacuum:
  - platform: miio2
    host: 192.168.0.139
    token: XXXXXXXXXXXXXXXXX
    name: Viomi SE

shell_command:
  kuchnia_on_off: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=7"
  kuchnia_vol_up: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=9"
  kuchnia_mute: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=8"
  kuchnia_vol_down: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=10"
  kuchnia_up: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=2"
  kuchnia_down: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=3"
  kuchnia_1: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=115"
  kuchnia_2: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=116"
  kuchnia_3: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=117"
  kuchnia_4: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=118"
  kuchnia_5: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=119"
  kuchnia_6: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=120"
  kuchnia_7: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=121"
  kuchnia_8: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=122"
  kuchnia_9: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=123"
  kuchnia_left: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=4"
  kuchnia_right: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=5"
  kuchnia_enter: "curl -H 'Authorization: Basic c3UzZzRnbzZzazc6amkzOTQ1NHh1L14=' http://192.168.0.142/Sendkey?key=6"

Just change the name and IP adress. Thanks for all the help with testing.

If you have trouble with getting drop down menu type in you browser IP/init and then try again.

V1.0 is here, the setup is via GUI, you can then reload the integration without restarting HA!

Removed manual configuration for my Radio from configuration.yaml. Updated to 1.1V and added though Guy → Everything worked perfectly.

Status updates with new version:

  • Toggle Power button works but does not update integration when powered on. (still need to use the quick on-off to do the testing)
  • Drop down menu is back and fully functional now.
  • Changing station though integration updates station icon.
  • Changing station manually does not update the station icon.
  • Volume up, down and slider work perfectly.
  • Mute icon works but does not get updated (does not change to🔇when mute is on)
  • Volume slider works for setting volume but does not get updated (when changes are made on :speaker:+ or :speaker:- buttons)
  • :previous_track_button:, ‖and :next_track_button: appear in the card but have no function.

Will try follow your instructions and test your remote as soon as possible, and will feedback also.

Thank you for your work and congratulations on the fast progress.

You may have to wait for about 10 seconds to get the info back, the radio has a slow response time and I limited the number of requests from the HA to limit the chance of freezing the radio.

https://i.imgur.com/jnc1Y2q.mp4

Same as above, up to 10s for update to the card.

I’ve tested it on two of my radios and they do work, but to bee sure send me what you get from IP/background_play_status and also can you turn on debugging for my integration and then after some time using it turn it off, you will get a download promt for a log which you can then send to me.

Przechwytywanie

It’s the last option.

The keys are sending code 31 and 32 so next and previous track, there is an option to set :next_track_button: to key 112 which will tell it to go to the next favorite station, but it will always start at the first favorite station and then go to the next one. There is no option on the radio to go to the previous favorite station :rofl:

On one of my radios the next track call changes the station, but on the other it does nothing, I think different makers went with different approach to the remote. You can type in IP/Sendkey?key=112 and check if your radio will switch to next favorite station.

Tested pressing the power button an waiting 2 minutes Integration still reports Radio as Off although it is playing internet radio. same thing with control buttons.

IP/background_play_status

<result>
<sid>6</sid>
<playtime_left>00:00:00</playtime_left>
</result>

Debug log file can be found in: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free

IP/Sendkey?key=112 switches to the next favorite station but integration does not get updated until I change volume on it for example.

IP/playinfo always reports the right and updated radio info:

<result>
<vol>5</vol>
<mute>0</mute>
<status>A Reproduzir </status>
<sid>6</sid>
<stream_format>MP3 /256 Kbps</stream_format>
<logo_img>http://#MYAIRPLAYRADIOIP:8080/playlogo.jpg</logo_img>
</result>

OK, I think i see where the problem is! Your radio does not brodcast volume info from /background_play_status like on my radios, I’ve changed get vol and mute info from /playinfo, also mapped the :next_track_button: to key 112 next favorite. Check out version 1.2 and let me know if this works ok.

Thank you for the logs and info, I would not have figured that out by myself!

Hey Dominik, Amazing work.

I think 1.2 is golden for all control features:

  • Radio Status integration update works. (capable of getting updates from changes made locally and remotely).
  • On/off/buffering status update to the instance.
  • :next_track_button: changes to the next track.
  • Volume and mute work and get correct feedback.
  • Station logo updated in instance in up to 10 seconds.

Congratulations on a great work…
… If you still have the time an the will I can suggest the following relevant features to add to the integration:

  1. Integrate the timer button (maybe to the non working :previous_track_button: (and get timer set/ time left displayed in the integration. (not sure how to collect info from which IP/URL.
  2. Airplay app supports direct broadcast from local files, to be able to use it inside the home assistant integration could be very interesting.

Once again amazing work.

1 Like

Great to hear that!

First lets try to see if we can use the :previous_track_button:, try IP/Sendkey?key=12 and tell me if that is what you want, here: https://github.com/DominikWrobel/airmusic/tree/main/remote you can check every remote command I could find and you can try them out to see what fits you.

For local file play I know it can be done via the app, but via the url I could never get it to work (but I did not spend much time on it). You can try to do it and give me feedback if it works:

IP/LocalPlay?url= and add a link to your local media something like http://192.168.0.90/Volume_1/Muzyka/GarbageParanoid.mp3&name=GarbageParanoid

Maybe from HA it would work better. If you like my work give me a star on github, and if you want buy me a coffe via this site: https://homeassistantwithoutaplan.wordpress.com/

Yes IP/Sendkey?key=12 activates a sleep timer for 15 minus. and on the radio display the timer runs down. (but I’m not sure if there is a URL to get the status of this timer we can collect back to the integration.

Preliminary testing for a valid URL showed that even with the airmusic app direct streaming works very erratic even trying to collect a test mp3 I put on-line it is not possible:
IP/LocalPlay?url=https://audio.jukehost.co.uk/gJWDjFFliHheBDnlyb4vmqBL3mCcNSoX
I will work in it to find the root cause.

Also noticed the integration is making a warning on the logs:

Logger: homeassistant.helpers.frame
Source: helpers/frame.py:151
First occurred: 9:06:40 AM (1 occurrences)
Last logged: 9:06:40 AM

Detected code that calls async_forward_entry_setup for integration airmusic with title: Ferguson and entry_id: *******, during setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1. Please report this issue.

Your airmusic repository in Guthub already has my star. And enjoy your Coffe on me. :slight_smile:

If you send the key=12 to the radio it will set the timer to 15 minutes, then on another press it will add 15 min until 180 minutes total is reached and will reset. I can map the :previous_track_button: to key 12 in the next release. There is no way to see what time is left on the sleep timer, the radio does not send that information. We could set up a helper to count the number of times the key was pressed and then countdown, maybe just maybe I can get this to work in the integration.

Local play does not work for me, but just maybe I can get this to work with HomeAssistant, I will try to setup a browse_media to work with this integration and test it out to see if anything works. But this may take some time and I make no promises.

The warning you are getting is because this integration supports for now both the yaml and GUI setup, in the future release I will switch to GUI only and it should go away.

Thank you for support!

EDIT:
Well the sleep timer thing turned out to be simpler than I thought :rofl: Look at the screen if this is how you want it to look, the timer changes every 10s or so.

sleep

You are becoming an expert at this. :sweat_smile:

When a 1.3 version is ready I’ll test the timer for sure. the timer was programed locally to match the one on the radio. Right? since there was no way to get the info from the radio’s feedback URL.

Yes in the integration itself, so if you set the timer from remote or on the radio it will not show up. I have to do some more testing before release, but later today or tomorrow it will be out. I have one little problem that when the radio turns off from sleep command it will be shown as on in HA :rofl:

Problem fixed, 1.3 is out, happy testing!