svrooij / sonos2mqtt

:speaker: Sonos mqtt controller. Control your speakers from your mqtt server. mqtt-smarthome insprired.
https://sonos2mqtt.svrooij.io/
MIT License
76 stars 18 forks source link

[feature request] having bass and treble state retain somewhere #114

Closed 10w73 closed 4 years ago

10w73 commented 4 years ago

For an EQ integration into homekit I need to read bass and treble. Is it possible to have them both retain somewhere at the same time? …/status/eq would be great. Unfortunately I'm not much of as .js guy.

github-actions[bot] commented 4 years ago

:tada: This issue has been resolved in version 3.0.10-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

10w73 commented 4 years ago

Thx for doing this so quickly. However it only shows the last changed of the two in the main status object. I need to see them both at every the time. I think this is also intended behaviour.

Edit: It actually shows both for the first time after sonos2mqtt starts. Then it just populates what was changed last.

I'm not even quite sure what I am doing (as I said, completely new to JavaScript) there but adding:

d.Events.on(sonos_1.SonosEvents.RenderingControl, (data) => { this.mqtt.publish(status/${this.topicId(d.Name, d.Uuid)}/eq, {bass: data.Bass, treble: data.Treble}, { qos: 0, retain: true }); });

to what should happen if you place the --distinct flag I. E. generates:

Client mosqsub/3752-raspione received PUBLISH (d0, q0, r0, m0, '/wg_ll/sonos/status/portable/eq', ... (22 bytes)) /wg_ll/sonos/status/portable/eq {"bass":0,"treble":-2} Client mosqsub/3752-raspione received PUBLISH (d0, q0, r0, m0, '/wg_ll/sonos/status/portable/eq', ... (11 bytes)) /wg_ll/sonos/status/portable/eq {"bass":-2} Client mosqsub/3752-raspione received PUBLISH (d0, q0, r0, m0, '/wg_ll/sonos/status/portable/eq', ... (11 bytes)) /wg_ll/sonos/status/portable/eq {"bass":-5} Client mosqsub/3752-raspione received PUBLISH (d0, q0, r0, m0, '/wg_ll/sonos/status/portable/eq', ... (12 bytes)) /wg_ll/sonos/status/portable/eq {"treble":3} Client mosqsub/3752-raspione received PUBLISH (d0, q0, r0, m0, '/wg_ll/sonos/status/portable/eq', ... (12 bytes)) /wg_ll/sonos/status/portable/eq {"treble":3}

Same thing happens to the status object.

svrooij commented 4 years ago

The above output doesn't really help, the data coming from the sonos2mqtt doesn't look like that.

Sonos only emits properties with the events if they have changed since the last time. This app does some "caching" to present the user with a complete status, but apparently this line also removes data if set to undefined in the update object.

10w73 commented 4 years ago

The broker is mosquitto and it looks exactly like that when adding the lines of code I mentioned earlier after: if(this.config.distinct === true) in the sonos-to-mqtt.ts file.

10w73 commented 4 years ago

How frequently do you think I could call getBass and getTreble via an adv_command to route the output to I. E. .../eq/bass and .../eq/treble in order to read that instead?

svrooij commented 4 years ago

Let's keep it at a difference in language interpretation.

How frequently do you think I could call getBass and getTreble via an adv_command to route the output to I. E. .../eq/bass and .../eq/treble in order to read that instead?

once a second, I guess (it depends on your sonos speakers to respond quick enough.)

In all the apps I use to connect to mqtt, the output of the player status looks like the sample below.

Anyhow, the status object will keep the last value for bass and treble in this release. So they are available there, and won't get removed with an update that doesn't have the values set.

{
  "uuid" : "RINCON_000E5000000001400",
  "name" : "Kantoor",
  "groupName" : "Kantoor",
  "coordinatorUuid" : "RINCON_000E5000000001400",
  "currentTrack" : {
    "Album" : "Hard Bass 2012 Mixed by The Pitcher, Luna, Frontliner and Chris One",
    "Artist" : "Pavo",
    "AlbumArtUri" : "http://192.168.1.105:1400/getaa?s=1&u=x-sonos-spotify:spotify:track:3Je8RHcdTJ8NGG3krmCHUd%3fsid%3d9%26flags%3d8224%26sn%3d7",
    "Title" : "Let’s Go! - Radio Edit",
    "UpnpClass" : "object.item.audioItem.musicTrack",
    "Duration" : "0:04:06",
    "ItemId" : "-1",
    "ParentId" : "-1",
    "TrackUri" : "x-sonos-spotify:spotify:track:3Je8RHcdTJ8NGG3krmCHUd?sid=9&flags=8224&sn=7",
    "ProtocolInfo" : "sonos.com-spotify:*:audio/x-spotify:*"
  },
  "transportState" : "PLAYING",
  "playmode" : "SHUFFLE",
  "ts" : 1586344373119,
  "volume" : {
    "Master" : 7,
    "LF" : 100,
    "RF" : 100
  },
  "mute" : {
    "Master" : false,
    "LF" : false,
    "RF" : false
  },
  "treble": 0,
  "bass": 0
}
10w73 commented 4 years ago

Ah! Great to hear that. Thank you!

I still have the problem that after starting sonos2mqtt it seems to work and I get something like that:

{"uuid":"RINCON_48A6B8E4276E01400","name":"Move","groupName":"Move","coordinatorUuid":"RINCON_48A6B8E4276E01400","currentTrack":{"Album":"Soft Planet - EP","Artist":"Sweeps","AlbumArtUri":"http://192.168.178.49:1400/getaa?v=0&vli=1&u=290294128","Title":"Red Helix","UpnpClass":"object.item.audioItem.musicTrack","Duration":"0:01:58","ItemId":"-1","ParentId":"-1","TrackUri":"undefined"},"enqueuedMetadata":{"Title":"","UpnpClass":"object.item.audioItem.linein.airplay","ItemId":"-1","ParentId":"-1"},"nextTrack":{"UpnpClass":"object.item.audioItem.musicTrack","ItemId":"-1","ParentId":"-1"},"transportState":"PLAYING","playmode":"NORMAL","ts":1596300302633,"volume":{"Master":21,"LF":100,"RF":100},"mute":{"Master":false,"LF":false,"RF":false},"bass":-10,"treble":0}

but after changing bass or treble it behaves like before and just keeps the changed value:

{"uuid":"RINCON_48A6B8E4276E01400","name":"Move","groupName":"Move","coordinatorUuid":"RINCON_48A6B8E4276E01400","currentTrack":{"Album":"Lifted Quest - EP","Artist":"J. Raise, Jr","AlbumArtUri":"http://192.168.178.49:1400/getaa?v=0&vli=1&u=832534634","Title":"Junkyard","UpnpClass":"object.item.audioItem.musicTrack","Duration":"0:02:41","ItemId":"-1","ParentId":"-1","TrackUri":"undefined"},"enqueuedMetadata":{"Title":"","UpnpClass":"object.item.audioItem.linein.airplay","ItemId":"-1","ParentId":"-1"},"nextTrack":{"UpnpClass":"object.item.audioItem.musicTrack","ItemId":"-1","ParentId":"-1"},"transportState":"PLAYING","playmode":"NORMAL","ts":1596300407733,"treble":-10}

In this case it was treble set to -10 and the info about the bass value is gone.

It think you are on the right track. I also started sponsoring your efforts right away.

svrooij commented 4 years ago

Can you do a sonos2mqtt --version (if running locally) or at least check you have the latest version, at my machine i'm getting both values. Running 3.0.10-beta.2 this release

I've updated to and from 0 and every time the last message actually has both values.

10w73 commented 4 years ago

Arghhh … of course it was 3.0.10-beta.1. Yesterday i didn't use the npm install -g option and it somehow got stuck local and messed up the PATH. It is working. Great job!

github-actions[bot] commented 4 years ago

:tada: This issue has been resolved in version 3.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: