Trigger a flow when a dumb external CD player starts playing

This is a long shot ... but there may be someone who has done something like this before.

I have an ancient CD player which my wife likes to use. I'd like to be able to detect when it starts playing to trigger a flow I can configure to ensure the playback amp is powered on and the right input selected.

My Node-RED is running on a RPi4. I was wondering if the RPi4 could detect an audio stream if I got an analogue to digital USB soundcard, for example, but I've not been able to find anything online that looks relevant. Perhaps I haven't managed to ask the right question in my searches. Has anyone any suggestions for me to explore?

It is not clear to me how the external CD player is “connected” with your raspberry pi.

I think he is suggesting using an audio feed to do it... but then if the amp isn't switched on how would the Pi hear the audio in the first place... catch-22.

I would expect that if everything is setup well and you use pulseaudio (you might need to install it) that you would see at least an extra pulseaudio source (= audio input) when using command pactl list sources.

E.g. (in my case I had to set PULSE_SERVER)

[root@nuc1 ~]# export PULSE_SERVER=unix:/run/user/1041/pulse/native; pactl list sources
Source #1
        State: RUNNING
        Name: alsa_input.pci-0000_00_0e.0.analog-stereo
        Description: Built-in Audio Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 6
        Mute: no
        Volume: front-left: 19592 /  30% / -31.46 dB,   front-right: 19592 /  30% / -31.46 dB
                balance 0.00
        Base Volume: 5206 /   8% / -66.00 dB
        Monitor of Sink: n/a
        Latency: 654100 usec, configured 2000000 usec
        Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
        Properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = "ALC283 Analog"
                alsa.id = "ALC283 Analog"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "0"
                alsa.card_name = "HDA Intel PCH"
                alsa.long_card_name = "HDA Intel PCH at 0x91410000 irq 131"
                alsa.driver_name = "snd_hda_intel"
                device.bus_path = "pci-0000:00:0e.0"
                sysfs.path = "/devices/pci0000:00/0000:00:0e.0/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "5a98"
                device.product.name = "Celeron N3350/Pentium N4200/Atom E3900 Series Audio Cluster"
                device.form_factor = "internal"
                device.string = "front:0"
                device.buffering.buffer_size = "352800"
                device.buffering.fragment_size = "176400"
                device.access_mode = "mmap+timer"
                device.profile.name = "analog-stereo"
                device.profile.description = "Analog Stereo"
                device.description = "Built-in Audio Analog Stereo"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        Ports:
                analog-input-internal-mic: Internal Microphone (type: Mic, priority: 8900, availability unknown)
                analog-input-mic: Microphone (type: Mic, priority: 8700, not available)
        Active Port: analog-input-internal-mic
        Formats:
                pcm

Source #17
        State: SUSPENDED
        Name: alsa_output.pci-0000_00_0e.0.hdmi-stereo.monitor
        Description: Monitor of Built-in Audio Digital Stereo (HDMI)
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 48000Hz
        Channel Map: front-left,front-right
        Owner Module: 6
        Mute: no
        Volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor of Sink: alsa_output.pci-0000_00_0e.0.hdmi-stereo
        Latency: 0 usec, configured 0 usec
        Flags: DECIBEL_VOLUME LATENCY 
        Properties:
                device.description = "Monitor of Built-in Audio Digital Stereo (HDMI)"
                device.class = "monitor"
                alsa.card = "0"
                alsa.card_name = "HDA Intel PCH"
                alsa.long_card_name = "HDA Intel PCH at 0x91410000 irq 131"
                alsa.driver_name = "snd_hda_intel"
                device.bus_path = "pci-0000:00:0e.0"
                sysfs.path = "/devices/pci0000:00/0000:00:0e.0/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "5a98"
                device.product.name = "Celeron N3350/Pentium N4200/Atom E3900 Series Audio Cluster"
                device.form_factor = "internal"
                device.string = "0"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        Formats:
                pcm
[root@nuc1 ~]# 

I suggest to check if the state changes when playing audio from your CD player. If so, you can poll this command every X minutes by a node-red execute node:

The cd player could be plugged in to a smart socket which can monitor power consumption.

My node-red knows when my coffee machine is on because the smart socket sends "current consumption" 1200W. Not sure how well it would recognise a low power device.

@janvda @jbudd I suspect those solutions would just detect that the player was powered and connected to the pi, rather than actually playing.

Thanks for taking the time to make these suggestions. I was initially thinking that USB audio devices are cheap and easily available, but the software side is perhaps tricky, if not impossible. Also there's a lot of CPU overhead listening all the time when all I'm after is an infrequent change of state that needs to be detected and reported promptly.

I had another idea which is to use the existing Node-RED RPi GPIO module, and find a way of making a physical connection. The chain might look like a device to detect that the optical signal on the CD's TOSLINK has gone live triggering a 12v (such as the Bobwire DAT1) connected to a micro relay, connected to the RPi GPIO. Since the DAT1 doesn't seem to be available in the UK, and it's expensive, then unless I find something else I may have to try and build my own. But this feels like a hardware hammer to crack this very small nut, rather than a software sledgehammer.

Can you hack the player?
If so, you could inline a sensor that detects power to an LED that comes on when the device is playing, or similar.
Or, if there is a physical play button that gets depressed, add contacts underneath it.

Or attach a light sensor over the front of the LED.

I admit that it is not clear to me which playback amp you want to power and which input you want to select. I am a bit puzzled about your actual Hardware setup.

It looks like I might have to hack something to make it work. But the only times I've used a soldering iron is to make up audio cables ... electronics is unchartered territory for me. Happy to have a go, but don't really know how to start.

I am using a TP=LINK KASA 115 to accurately detect between accurate 0mA and 10 mA to determine if an LED light is turned on in an overhead fan assembly.

I use this info to turn cooking lights on/off. 100% reliable1

Here is the output from the sensor. It might be able to detect the difference between the CD player being on/playing.

10 WATT LEDS ON
~current_ma: 48
~voltage_mv: 236537
~power_mw: 10354
~total_wh: 1258
~err_code: 0
~current: 0.048
~power: 10.354
~total: 1.258
~voltage: 236.537
~timestamp: "2021-12-04T09:37:59+11:00"

10 WATT LEDS OFF:
~current_ma: 0
~voltage_mv: 236575
~power_mw: 0
~total_wh: 1259
~err_code: 0
~current: 0
~power: 0
~total: 1.259
~voltage: 236.575
~timestamp: "2021-12-04T09:41:29+11:00"

Thanks @RichdeCrep. That's great to hear that a smart socket like @jbudd first suggested does work to detect usage of such low power devices. I've checked the specs of the CD player and it looks like usage changes from "<3W in standby state" to "25W Typically use", so worth trying as a first step. The TP Link KP115 usually sells for around ÂŁ15, but seems to be sold out in the UK right now. I think I'll either wait or look for an alternative if it takes too long to restock. Thanks again.

There are lots of smart plugs available with energy monitoring.
Many of them turn your devices on and off via servers in China, which they dress up as a wonderful smart phone app.
The ones I use have been reflashed with Tasmota open source firmware. Unfortunately it's difficult to know which brands you can do that with; it relies on the PLC being an ESP8266 and an unfixed bug in the provided firmware.
So my new year's resolution is only ever to buy new ones from Athom since they have Tasmota out of the box https://www.athom.tech/blank-1/uk-plug

1 Like

Use zigbee devices. No info outside house then :grinning:

That sounds good. Can you make any specific recommendations for UK plugs?

I am getting a Samsung GP-WOU019BBDWG zigbee smart plug which I hope will do the job, but I haven't got it yet, in fact I won't have it till Christmas. ÂŁ19.95 https://www.amazon.co.uk/gp/product/B07TK4CC42
There are cheaper ones but I decided it wasn't worth trying to save a few pounds.

1 Like

I only have 3 at the moment (ZigBee Smart Plug 16A UK Socket Tuya Smart Life APP Work With Alexa Google Home Assistant Voice Control Power Monitor Timing|Home Automation Modules| - AliExpress) so I cannot really make recommendations. (The only one I would make is treat any current ratings above 13A with a pinch of salt) These particular plugs report current, voltage, instantaneous power & accumulated kWh

Amazon sell zigbee smart plugs but AliExpress are cheaper (although they take longer to arrive)

I run all my zigbee devices through zigbee2mqtt and Node-RED so no apps required. I use the node-red-contrib-googlehome node to allow Google voice control but there are other nodes available (also for Alexa)

1 Like

Thanks @Colin and @Buckskin - all really helpful suggestions. I think I can assemble the solution from this information, although it may take a little time to get the hardware. Thanks again.

Well since the socket it is being plugged into is only rated at 13A then that is definitely the case. I usually rate such devices at about half of what they say.