Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Last active March 28, 2024 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/74bebe3ab773348d3386cf2e5f3f1a06 to your computer and use it in GitHub Desktop.
Save gitfvb/74bebe3ab773348d3386cf2e5f3f1a06 to your computer and use it in GitHub Desktop.
Some notes about the usage of hyperion

Here I can write down some notes

import requests
import json
# settings
url = 'http://192.168.2.154:8090/json-rpc'
effects=["Knight rider", "Atomic swirl", "Rainbow swirl fast"]
# create a session
s = requests.Session()
# Switch to effect instance
switchjson = {'command': 'instance', 'subcommand': 'switchTo', 'instance': 1 }
i = s.post(url, json = switchjson)
# Find out the active effect
activeEffectsJson = {'command': 'serverinfo', 'tan': 1 }
si = s.post(url, json = activeEffectsJson )
info = si.json()
j = 0
if len(info['info']['activeEffects']) > 0 :
# body of if statement
activeEffectName = info['info']['activeEffects'][0]['name']
i = effects.index(activeEffectName)
j = i+1
# end of list reached
if j >= len(effects) :
j = 0
# Change effect
effectjson = {'command': 'effect', 'effect': {'name': effects[j]}, 'priority': 50 }
e = s.post(url, json = effectjson)
print (e.text)
import requests
import json
# settings
url = 'http://192.168.2.154:8090/json-rpc'
effects=["Knight rider", "Atomic swirl", "Rainbow swirl fast"]
# create a session
s = requests.Session()
# Switch to effect instance
switchjson = {'command': 'instance', 'subcommand': 'switchTo', 'instance': 1 }
i = s.post(url, json = switchjson)
# Find out the active effect
activeEffectsJson = {'command': 'serverinfo', 'tan': 1 }
si = s.post(url, json = activeEffectsJson )
info = si.json()
j = 0
if len(info['info']['activeEffects']) > 0 :
# body of if statement
activeEffectName = info['info']['activeEffects'][0]['name']
i = effects.index(activeEffectName)
j = i-1
# end of list reached
if j < 0 :
j = len(effects) -1
# Change effect
effectjson = {'command': 'effect', 'effect': {'name': effects[j]}, 'priority': 50 }
e = s.post(url, json = effectjson)
print (e.text)
!/bin/bash
#instance=$( curl --header "Content-Type: application/json" --request POST --data '{"command":"serverinfo","tan":1}' http://192.168.2.154:8090/json-rpc | jq --raw-output '.instance' )
# Find out the status of the second instance for effects. If it is not running, start it. Otherwise switch back and turn it off
instance=$(curl --header "Content-Type: application/json" --request POST --data '{"command":"serverinfo","tan":1}' http://192.168.2.154:8090/json-rpc | jq --raw-output '.info.instance[] | select(.instance==1)>
if [ $instance = false ]; then
curl --header "Content-Type: application/json" --request POST --data '{ "command": "componentstate", "componentstate": {"component": "ALL", "state": false} }' http://192.168.2.154:8090/json-rpc
curl --header "Content-Type: application/json" --request POST --data '{ "command": "instance", "subcommand": "startInstance", "instance": 1 }' http://192.168.2.154:8090/json-rpc
curl --header "Content-Type: application/json" --request POST --data '{ "command": "instance", "subcommand": "switchTo", "instance": 1 }' http://192.168.2.154:8090/json-rpc
else
curl --header "Content-Type: application/json" --request POST --data '{ "command": "instance", "subcommand": "stopInstance", "instance": 1 }' http://192.168.2.154:8090/json-rpc
curl --header "Content-Type: application/json" --request POST --data '{ "command": "instance", "subcommand": "switchTo", "instance": 0 }' http://192.168.2.154:8090/json-rpc
curl --header "Content-Type: application/json" --request POST --data '{ "command": "componentstate", "componentstate": {"component": "ALL", "state": true} }' http://192.168.2.154:8090/json-rpc
sleep 5s
curl --header "Content-Type: application/json" --request POST --data '{ "command": "componentstate", "componentstate": {"component": "SMOOTHING", "state": true} }' http://192.168.2.154:8090/json-rpc
fi
@gitfvb
Copy link
Author

gitfvb commented Mar 27, 2024

The switch of the mode works fine, but for changing the instance and keep it, it is necessary to hold the session. It seems like the curl command creates a new session with every call. To solve this I have used python rather than shell scripting and it works to change the instance (and keep it) and then change effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment