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