Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Last active November 1, 2024 18:32
Show Gist options
  • 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 Nov 1, 2024

Good hints to allow access to the linux machine without entering password:
https://linuxize.com/post/how-to-setup-passwordless-ssh-login/

The hints here did the missing part to connect without password: https://forums.raspberrypi.com/viewtopic.php?t=226203

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