Zum Ende der Metadaten springen
Zum Anfang der Metadaten


Author

Aleš Berka (Aleq)

Logo

Status

PRIVATEBETA

Version0.2.30
Compatibility

LB 0.2.3LB 1.2.2

Downloadclosed beta at loxforum, public version coming soon
PurposeBasic Chromecast (audio) control for Loxone

 Version History...

Version 0.1

  • development, proof of concept, initial version

Version 0.2

  • first fully working version

Version 0.2.12

  • private beta test

Version 0.2.25

  • bug fixes

Version 0.2.27

  • Chromecast connection status reporting

Version 0.2.28

  • Better logging (easier to see invalid commands)

Version 0.2.29

  • QUIT command fixed

Version 0.2.30

  • rounding bug fixed (ADJUST_VOLUME over 29 etc.)




Content




Download

Public version not yet ready, but I'm looking for BETA TESTERS! If you are interested, send an email to ales DOT berka DOT dev AT gmail


Installation

Requires LoxBerry 1.2.2+

  1. Follow the standard installation procedure to install the plugin, just link/upload the ZIP file in/to the LoxBerry Plugin Management.
  2. After the installation, head to the plugin pages in the LoxBerry Web UI and enter the Configuration.
  3. Return to Overview once finished to validate the configuration:
    1. LoxBerry status should say "server running". If not, check your configuration of UDP Port and restart LoxBerry, if still not OK. Check Log, still not OK
    2. Chromecast status should say "Connected". If not, check your configuration of Chromecast IP. Make sure the Chromecast is on the same network (same sub net). See Troubleshooting, tips below
    3. "Replies will be sent to:" section shows the configured Loxone target. Optional.


Plugin function

Plugin contains a server, which listens for UDP commands coming from Loxone Miniserver, performs desired actions on Chromecast and replies results back to Loxone via another UDP transmission.

Supported Chromecast actions:

  • Query status
  • Query volume
  • Get notified of volume changes
  • Control volume (both absolute and relative)
  • Play (cast) a stream
  • Pause/Stop current cast
  • Quit current application


Configuration

Plugin needs to be configured first. You need to set:

  • UDP port (where the plugin accepts UDP commands)
  • Chromecast address (if you don't know it, try Discover tab in the plugin, it scans LAN for Chromecasts and lists their IPs)
  • Loxone Miniserver IP address and UDP port (where to send the replies). This is optional. If you don't want to receive result (or to query the volume), you don't need to configure it.
  • Periodic volume change detection. This is optional. If defined (as a number of seconds), enabled active polling for volume change compared to last known value. The configured time is the amount of seconds how often or how soon after last command is the volume polled. This polling happens on LoxBerry. If a volume change is detected, then (and only then) the message is sent to Loxone Miniserver (ie. Loxone isn't receiving periodic messages unless there's a change). If you need periodic reporting to Loxone, query the volume (using GET_VOLUME command described below) on your own.


Loxone Config

To control Chromecast:

  1. Create Virtual Output, as address use udp://<loxberry_ip>:<configured_udp_port>
  2. Under this Virtual Output, create desired Virtual output commands. This is a list of supported functions (to be entered into "Command for ON"):
    1. GET_STATUS
    2. GET_VOLUME
    3. SET_VOLUME <v> (Uncheck Use as digital output and copy paste the command including the angle brackets and "v" (less-than and greater_than signs)!
    4. ADJUST_VOLUME 5 (feel free to change 5 to a different number, if you want bigger or smaller volume increase in one step)
    5. ADJUST_VOLUME -5 (feel free to change -5 to a different number, if you want bigger or smaller volume decrease in one step)
    6. PLAY stream_url
    7. PAUSE
    8. QUIT

To receive replies from plugin (OPTIONAL, simple version):

  1. Create Virtual UDP Input, pick any port number, put it into "UDP receive port" and also into the Chromecast 4 Lox configuration, field "Loxone UDP Port"
  2. Under this Virtual UDP Input, add Virtual UDP input commands:
    1. Volume
      1. Uncheck Signed values
      2. Command recognition: "VOLUME \v;" without quotes
      3. Unit: "<v>" without quotes
      4. Minimum value: 0
      5. Maximum value: 100

You can use the UDP monitor (feature of Loxone Config) to explore the replies


UDP communication

You can send multiple commands at once, separated by semicolon ( ; ). Replies always start with asterisk ( * ) and end with semicolon ( ; ). There is no escaping at the moment

Commands (received and recognized by Chromecast 4 Lox)

GET_STATUS

Checks the Chromecast status. Returns free text returned from builtin Chromecast controlling utility prefixed by "STATUS:\n" and ended by ";"

Sample response:

*STATUS:
Connecting to 192.168.1.51:8009...
Connected
[Default Media Receiver] Default Media Receiver
Volume: 0.41
;


GET_VOLUME

Queries Chromecast volume, which is returned as integer value 0-100, prefixed by "*GET_VOLUME_ACK " (including the space) and ended by ";"

Possible responses are:

      • *GET_VOLUME_ACK number;   (if succeeded)
      • *GET_VOLUME_NACK;             (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)

Sample response:

*GET_VOLUME 41;

SET_VOLUME

Sets the new volume level. Command format "SET_VOLUME number" where number is the volume level, integer, 0-100.

Possible responses are:

      • *SET_VOLUME_ACK number;   (if succeeded)
      • *SET_VOLUME_NACK;              (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)

ADJUST_VOLUME

Adjusts the new volume level by defined difference (positive or negative for volume increase or decrease). Command format "ADJUST_VOLUME delta" where delta is the volume difference, integer, -100..100, to be added to the current volume level. The purpose of this function is accommodate volume up and volume down operations.

Possible responses are:

      • *ADJUST_VOLUME_ACK number;   (if succeeded; number represents the resulting (new) absolute volume level)
      • *ADJUST_VOLUME_NACK;              (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)


Sample command:

ADJUST_VOLUME -10;


Sample response (from a Chromecast having a volume level 65 before the command was processed):

*ADJUST_VOLUME_ACK 55;

PLAY <url>

Plays (casts) remote stream (defined by URL) on Chromecast. Supported formats rely completely on Chromecast, LoxBerry plugin passes just the URL. Command format "PLAY url" where url is the address of the stream. From the Chromecast Help, Chromecast Audio supports: HE-AAC, LC-AAC, MP3, Vorbis, WAV (LPCM), Opus, FLAC with support for high-resolution streams (24-bit/96KHz).

Possible responses are:

      • *PLAY_ACK url;   (if succeeded)
      • *PLAY_NACK;      (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)


Sample command:

PLAY http://amp.cesnet.cz:8000/cro1-256.ogg;


Sample response:

*PLAY_ACK http://amp.cesnet.cz:8000/cro1-256.ogg;

PAUSE

Pauses Chromecast playback. 

Possible responses are:

      • *PAUSE_ACK;     (if succeeded)
      • *PAUSE_NACK;  (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)

STOP

Stops Chromecast playback. 

Possible responses are:

      • *STOP_ACK;     (if succeeded)
      • *STOP_NACK;  (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)

QUIT

Closes current app on Chromecast

Possible responses are:

      • *QUIT_ACK;     (if succeeded)
      • *QUIT_NACK;  (if failed, for instance Chromecast was not reachable, in case of network issues, etc. For details check Log)


Messages sent to Loxone Miniserver (besides replies to commands described above)

Periodic volume notification

Periodic check of volume (if configured) sends "*VOLUME number;" messages to Loxone upon volume change, where number is the new volume level, integer, 0-100.

Sample message sent to Loxone Miniserver:

*VOLUME 5;

Connection status

Chromecast connection status is reported (if changes) after each communication with the device. Offline message is repeated after each failed attempt. Periodic repeating of the message can be configured on top of this. It is important to understand the status reporting period is dependent on any action on Chromecast. Without it will not report anything, ie. it is recommended to have Periodic volume notification enabled (and the Period of volume notifications should be less or equal to Connection status reporting period).

Messages sent to Loxone Miniserver:

      • *STATUS_ONLINE;
      • *STATUS_OFFLINE;


Sample message sent to Loxone Miniserver:

*STATUS_ONLINE;


Road map

To be considered:

  • Active monitoring for volume changes DONE (polling-based)
  • Volume up/down DONE.
  • Support M3U/PLS files as a casting source (medium priority)
  • Google Music All Access integration (no promises, no timelines, just a wish)
  • Active monitoring for volume changes (event-based) (very low priority)
  • Support multiple Chromecast devices (high priority)


Troubleshooting, tips

  • If you don't want to use "slightly less secure" WiFi on the same network as LoxBerry (Chromecast doesn't support WPA Enterprise/802.1x, only WPA2-PSK), consider Chromecast Ethernet Adapter. Even cheap 3rd party product from ebay/Aliexpress has proven to work great. You'll also get a nice bonus on top of the security - absolute connection stability
  • In case of any issue, check the Log
  • If the UDP server crashes, you'll need to restart the LoxBerry to get it up again


Known issues, limitations

  • Some ShoutCast/IceCast streams are not supported by Chromecast (nothing I can do about it, unless a conversion proxy is made, which is not in scope of this small plugin)


Questions, bug reports

Vodnici.net, czech Loxone forum

Loxforum.com closed beta applications and feedback

E-mail: ales.berka.dev at gmail 



14 Kommentare

  1. Thomas Bonte sagt:

    Just a shout out that the plugin works as expected. Terrific work ales! Looking forward to test multiple chromecast support (Lächeln)

    1. Thomas Bonte sagt:

      Fyi I hacked my way through it to add multiple chromecast support. It was removing 2 lines of code and adding 4. The IP address for each chromecast device is past on as a param in the UDP command.

      1. Aleš Berka sagt:

        A way to go, Thomas.

        TO All:

        Thinking of it, do you prefer specifying IP address (and actually also a port) of cast target (chromecast/...) in each request and have a lean LoxBerry plugin configuration or the other way around - ie. define and configure all allowed targets in LoxBerry plugin UI and then just use them from Loxone with simpler commands (referencing them by simple numer for instance)?

        A.

        1. Thomas Bonte sagt:

          An additional question: would you think it's required to reserve the IP address for each chromecast device? Or is that throwing too much burden on the user?

          1. Aleš Berka sagt:

            Do you mean to have a fixed IP address for each cast device? That would be actually good point as well, by default it is using DHCP and only power users do have it static (predefined in DHCP). I was just thinking about the same thing this morning by coincidence. An alternative would be to address the cast devices by name. I have to check that, though.

            1. Thomas Bonte sagt:

              In case of using devices by name or some unique id, then it would still have to be resolved to an IP address not? This name / ip mapping should be cached, otherwise it would take too long. And additionally, some solution would be needed to refresh mapping. So it becomes quite some coding work.

              1. Aleš Berka sagt:

                Not necessarily, the CLI tool I'm using supports addressing target by name only. It runs discovery at the beginning and stops upon match. Based on my observations, it is instantaneous, less than a fraction of a second.  On the other hand I have Chromecast on wired LAN

        2. I would go with the simplier Loxone commands and configuration in Loxberry

      2. Could you provide more details ? What do I need to change ? That would be most useful, as I have several chromecast devices.

        1. Koen Victor sagt:

          Hi Thomas, thank you for the inspiration, I had a look at it this weekend and that works - diff attached for those who may find it helpfull.

          diff_

  2. Mathias sagt:

    Looking forward to the release. good luck!

  3. Thomas Bonte sagt:

    Did anyone try to send commands to a chromecast speaker group? This feature doesn't seem to work for me, and I suspect it's because the right port is not taken into account. 

    1. Thomas Bonte sagt:

      So Aleš pointed out that the library this plugin is using is go-cast. The readme indicated that the library can handle the friendly chromecast device name as well (global option "--name"). So 

      $ cast --name Hifi media play http://amp.cesnet.cz:8000/cro1-256.ogg

      This way we can cast to speaker groups. This then also answer how to extend the Chromecast 4 Lox plugin for multiple Chromecast device support: not via IP but rather with Chromecast device name. The plugin needs to be able to handle device names with spaces and special characters.

      1. Aleš Berka sagt:

        On my wish list together with custom port and multiple chromecast devices...