Skip to content

Instantly share code, notes, and snippets.

@maxanier
Created January 29, 2023 16:20
Show Gist options
  • Save maxanier/2f3ec08b09d7931fd0c50ba830f5bd39 to your computer and use it in GitHub Desktop.
Save maxanier/2f3ec08b09d7931fd0c50ba830f5bd39 to your computer and use it in GitHub Desktop.
Openhab + Mopidy Control Integration

For Openhab v3 and Mopidy RPC 2.0

Install "HTTP" Binding and "JSON Path" transform. https://www.openhab.org/addons/bindings/http/ https://www.openhab.org/addons/transformations/jsonpath/ https://docs.mopidy.com/en/latest/api/http/

Create transforms/mopidycommand.map

playing={"jsonrpc":"2.0","id":1,"method":"core.playback.play"}
paused={"jsonrpc":"2.0","id":1,"method":"core.playback.pause"}
next={"jsonrpc":"2.0","id":1,"method":"core.playback.next"}
previous={"jsonrpc":"2.0","id":1,"method":"core.playback.previous"}

Create thing:

Thing http:url:mopidy "Mopidy" [
        baseURL="<mopidy-server-url>/mopidy/rpc",
        headers="Content-Type=application/json",
        commandMethod="POST",
        stateMethod="POST"]     {
                Channels:
                        Type player : music_status [
                                playValue="playing",
                                pauseValue="paused",
                                nextValue="next",
                                previousValue="previous",
                                stateTransformation="JSONPATH:$.result",
                                stateContent="{\"jsonrpc\":\"2.0\", \"method\":\"core.playback.get_state\",\"id\":1}",
                                commandTransformation="MAP:mopidycommand.map"]
}

Item definition:

Player MusicStatus "Music" {channel="http:url:mopidy:music_status"}

Connect to openhab console for debugging and set log level for http binding:

ssh -p 8101 openhab@localhost
log:set TRACE org.openhab.binding.http
log:tail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment