JSON swich for Hyperion-NG to turn on/off instance

Hello everyone,

i have a problem on who to configure a JSON Switch in Home Assistant.

My situation:
I’m having Hyperion-NG installed on a RP3b+ (with the HyperBian OS, works like a charm!) and the W2801 Leds behind my TV are controlled by an ESP8266 with WLED installed on it.
This also works without a problem, Hyperion gets the HDMI signal from my TV and sends the informations to the ESP8266.

Before i added an ESP, the Raspberry controlled the W2801 Leds directly, but i wantet to use the led strip also for other things, so reconfigured my setup, just for info^^

At the moment i have an rest switch in my HA config, which controls the UDP receiving from the WLED:
0 = allow
1 = override once
(2 would be override until reboot)

   - platform: rest
     name: Hyperion
     resource: http://192.168.188.55/json/state
     body_on: '{"lor": 0}'
     body_off: '{"lor": 1}'
     is_on_template: '{{value_json.lor == 0}}'
     headers:
       Content-Type: application/json

Also this is working without a problem, when the switch is on, the ESP controls the led strip with the data received from Hyperion, when the switch is off, i can control the ESP/WLED with the webui/HA integration like a normal led strip (with effects etc.)

Now i managed to install LedFX on my computer and i like it very much, BUT here i have a problem with it:
When the “Hyperion Switch” in HA is off, also LedFX doesn’t work, because the switch controls the UDP receiving from the WLED not Hyperion-NG directly.

So after a bit of research, i found two articles in the Hyperion-NG wiki:
https://docs.hyperion-project.org/en/json/#what-is-json
https://docs.hyperion-project.org/en/json/Control.html#control-instances

Although i have no idea on how to configure a JSON-RPC switch from Home Assistant to control an Hyperion instance.
It should start with http://Hyperion-IP:19444/json-rpc ; method: post ; and that’s all i know.

Could someone help me to configure the switch to turn on/off the instance in Hyperion with a JSON switch from Home Assistant?

I know i could go to the webserver of hyperion and do in manually, but having everything in HA is more comfortable and i don’t want to use other app/websites everytime.

Hoping someone has an idea :slight_smile:
Greetings

1 Like

So I found a solution by myself, little bit proud, because my skills in this metier are rather unavailable^^

The best way to turn on/off a instance in Hyperion through Home Assistant is to use rest commands.

I built two in my configuration.yaml, looking like this:

rest_command:
  ambi_on:
    url: "http://Hyperion-IP:8090/json-rpc"
    method: post
    content_type: "application/json"
    payload: '{"command":"instance","subcommand":"startInstance","instance":1}'
  ambi_off:
    url: "http://Hyperion-IP:8090/json-rpc"
    method: post
    content_type: "application/json"
    payload: '{"command":"instance","subcommand":"stopInstance","instance":1}

With a input bollean switch a created two automations, one activates “ambi_on”, when the input switch is switched to on and vice versa.

Now it works perfectly, the hyperion instance for the ESP8266 with WLED on it starts and uses the Hyperion data to control the leds, when switchting the input boolean to on and if i wanna use the leds for other things, I can control them normally through the WLED integration in HA (or LedFX in my case too^^) and I don’t have to worry, that Hyperion is fucking something up, because it receives a HDMI signal from something and starts to control the ESP, because the instance is turned off.

Hope this helps somebody else too :slight_smile:
Greetings

3 Likes

I use a rest_command, designed to control whichever components I specify:

rest_command:
  hyperion_component:
    url: 'http://hyperion_ip:port/json-rpc'
    method: 'POST'
    payload: '{"command": "componentstate", "componentstate": {"component": "{{ component }}", "state": {{ state }}}}'
    content_type: application/json

I then use:

switch:
  - platform: template
    switches:
      hyperion_v4l:
        friendly_name: Hyperion V4L
        value_template: "{{ is_state_attr('sensor.hyperion_components', 'v4l', 'on') }}"
        turn_on:
          service: rest_command.hyperion_component
          data:
            component: 'V4L'
            state: 'true'
        turn_off:
          service: rest_command.hyperion_component
          data:
            component: 'V4L'
            state: 'false'
        icon_template: mdi:usb-port

To enable/disable the “USB Capture” component. If you’re using platform capture, I believe changing 'V4L' to 'GRABBER' should do the same :+1:

1 Like

Can i use the same method for ledfx for switching it on and off
If yes how??
I tried but no result

Last time I used LedFX, it didn’t offer something like this.

hi there

I am struggling with the on/off command to control my hyperion instance via HA. I used the above command, changed the instance from 1 to 0 and pasted the below code in my config.yaml on my Raspi Pi 4.

rest_command:
  ambi_on:
    url: "http://Hyperion-IP:8090/json-rpc"
    method: post
    content_type: "application/json"
    payload: '{"command":"instance","subcommand":"startInstance","instance“:**0**}‘
  ambi_off:
    url: "http://Hyperion-IP:8090/json-rpc"
    method: post
    content_type: "application/json"
    payload: '{"command":"instance","subcommand":"stopInstance","instance“:**0**}

It seems that the command arrives at the Hyperion server but I get the following message in the log:

called ambi-off command service (192.168.1.46 is the HA-server)

2021-07-05T14:17:05.729Z [hyperiond HTTPJSONRPC] (DEBUG) (JsonAPI.cpp:81:handleInstanceSwitch()) Client '::ffff:192.168.1.46' switch to Hyperion instance 0

called ambi-on command service (192.168.1.46 is the HA-server)

2021-07-05T14:19:43.471Z [hyperiond HYPERION] (DEBUG) (HyperionIManager.cpp:116:startInstance()) Can't start Hyperion instance index '0' with name 'APA102' it's already running or queued for start

I would appreciate any help in order to get the on/off switch running in order to build automations.

Many thanks

Andrew

Why aren’t you using the default integration
It has been updates quite recently to include all on-off switches.

Because it’s broken since couple recent updates