Proairesis

Find Me On…

  • Facebook
  • tumblr
  • deviantArt
  • Storenvy
  • Home
  • About

Month: May 2022

Put your Twitch Chat in control

Posted on May 8, 2022 Leave a Comment

Follow these steps to set up WLED colour changes as channel point rewards using Kruiz Control. These instructions are written specifically for my Squid Lamps but can be modified for use with any WLED project.

Example video of this setup in action:

Tonight’s project! pic.twitter.com/YcWZjQHnWd

— Alecat (@alecatmew) April 7, 2022

EDIT updated 2022-12-21

Check out Riekelt’s project, KrakenCommand for an alternative setup!

https://github.com/riek-lt/KrakenCommand

Original post follows

Download Kruiz Control

https://github.com/Kruiser8/Kruiz-Control/releases

Download and extract these files to somewhere you can remember.

Edit the Kruiz Control settings files

Inside the Kruiz Control directory is a “settings” folder containing a number of files that configure plugins against various services.

We need to modify settings/chat/oauth.txt and settings/twitch/user.txt.

OAuth Token

Generating an OAuth token allows us to talk with the Twitch API.

https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=lavpr320qswa5w1whfcnpj6sb9lz7p&redirect_uri=https://twitchapps.com/tokengen/&scope=channel:manage:redemptions%20channel:read:redemptions%20chat:edit%20chat:read%20user:read:email

Click the above link to generate a token. You’ll be prompted to authorize permissions as a Twitch account.

Do not share this token with anyone else! It has permissions to manage your channel redemptions, to send messages in chat as the Twitch account that you choose and to see the email associated with the account. (I dunno why email address is needed but Comfy.js won’t work without that permission)

Open settings/chat/oauth.txt and replace the “token” part of the file with the generated token. Remove any spaces.

Channel Name

In settings/twitch/user.txt set the name of the channel that you want to watch for channel point redemptions. (Usually, your channel)

Chat User (Optional – not currently used)

Set settings/chat/user.txt to a Twitch channel. Setting this would allow Kruiz Control to send messages on your behalf to that channel.

Make the Custom Rewards in Twitch

https://dashboard.twitch.tv/viewer-rewards/channel-points/rewards

Make one reward per lamp colour.

Suggested list:

  • Rainbow Lamp
  • Blue Lamp
  • Cyan Lamp
  • Green Lamp
  • Yellow Lamp
  • Orange Lamp
  • Red Lamp
  • Magenta Lamp

Optional: icons in 112×112, 56×56 and 28×28 here: https://ale.chenonetta.com/stuff/ChannelPointIcons.zip 

Edit the Kruiz Control triggers.txt file

Replace the contents of triggers.txt with the following. Note that the OnChannelPoint triggers need to match the names of the rewards from the step above.

Replace the IP address on line 2 (http://192.168.0.113) with the IP of the lamp.

Your lamp needs to be connected to the same network as your streaming PC.

OnInit
API Url SquidBeakon "http://192.168.0.113/json/state"
API Method SquidBeakon POST
API Header SquidBeakon "Content-Type" "application/json"

OnChannelPoint "Rainbow Lamp"
API RawData SquidBeakon "{\"seg\": [{\"of\": 4, \"fx\": 110, \"sx\": 128, \"ix\": 128, \"pal\": 11}]}"
API Send SquidBeakon

OnChannelPoint "Blue Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[0, 0, 255]]}]}"
API Send SquidBeakon

OnChannelPoint "Cyan Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[0, 255, 200]]}]}"
API Send SquidBeakon

OnChannelPoint "Green Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[8, 255, 0]]}]}"
API Send SquidBeakon

OnChannelPoint "Yellow Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 200, 0]]}]}"
API Send SquidBeakon

OnChannelPoint "Orange Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 160, 0]]}]}"
API Send SquidBeakon

OnChannelPoint "Red Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 0, 0]]}]}"
API Send SquidBeakon

OnChannelPoint "Magenta Lamp"
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 0, 255]]}]}"
API Send SquidBeakon

Future enhancements:

There is a feature request to enable accepting or rejecting of channel point requests. https://github.com/Kruiser8/Kruiz-Control/issues/39

Once this is implemented, we can update the trigger code to refund channel points if the lamp failed to update, and clear items out of the queue if it’s successful.

Alternatively, we could write our own code using Comfy.js!

Twitch currently only allows cooldowns on a per-reward basis. Kruiz Control has the ability to track its own cooldowns. See https://github.com/Kruiser8/Kruiz-Control/blob/master/js/Documentation.md#cooldown

Add Kruiz Control as a browser source in OBS

Add a new browser source. Select “Local File” and pick the index.html file from the Kruiz Control directory that you extracted in step 1. Keeping this browser source active will listen for Channel Point redemptions.

Select a reward in Twitch and if everything has been set up correctly, the lamp colours will change!

If you make any changes to the files inside the Kruiz Control directory, including the settings or triggers.txt files, you must refresh your browser source in OBS for the changes to take effect.

Appendix: A single reward with user-provided colour

If you don’t want to crowd your rewards with the lamp options, you can create one reward and allow it to control the lamp colours with the redemption message from your viewers.

Using a single reward also allows for the Twitch cooldowns to be used. This means that a viewer can’t override the colours set by another viewer until the cooldown ends.

Replace triggers.txt with the text from the code block below. Create a single reward named “Set Lamp Color” and turn on the “Require Viewer to Enter Text” checkbox.

This trigger will search the text of the message that was attached to the points redemption and if one of the color keywords is found then the lamp colour will change. It’s worth suggesting to the user what to enter in their message in the reward description, eg:

Set my squid lamp to rainbow, blue, cyan, green, yellow, orange, red or magenta by including one of these words in your message!

OnInit
API Url SquidBeakon "http://192.168.0.113/json/state"
API Method SquidBeakon POST
API Header SquidBeakon "Content-Type" "application/json"

OnChannelPoint "Set Lamp Color"
Param Lower message
Param Keyword message "rainbow"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"of\": 4, \"fx\": 110, \"sx\": 128, \"ix\": 128, \"pal\": 11}]}"
API Send SquidBeakon
Exit
Param Keyword message "blue"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[0, 0, 255]]}]}"
API Send SquidBeakon
Exit
Param Keyword message "cyan"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[0, 255, 200]]}]}"
API Send SquidBeakon
Exit
Param Keyword message "green"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[8, 255, 0]]}]}"
API Send SquidBeakon
Exit
Param Keyword message "yellow"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 200, 0]]}]}"
API Send SquidBeakon
Exit
Param Keyword message "orange"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 160, 0]]}]}"
API Send SquidBeakon
Exit
Param Keyword message "red"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 0, 0]]}]}"
API Send SquidBeakon
Exit
Param Keyword message "magenta"
If 3 {matched} == true
API RawData SquidBeakon "{\"seg\": [{\"fx\": 0, \"col\": [[255, 0, 255]]}]}"
API Send SquidBeakon
Exit

Appendix: Customising Eye colours

Add the following trigger commands to triggers.txt. Make sure to create the corresponding rewards in the Twitch dashboard!

OnChannelPoint "Red Eyes"
API RawData SquidBeakon "{\"seg\": [{},{\"col\": [[255, 0, 0]]}]}"
API Send SquidBeakon

OnChannelPoint "Lime Eyes"
API RawData SquidBeakon "{\"seg\": [{},{\"col\": [[255, 255, 0]]}]}"
API Send SquidBeakon

OnChannelPoint "White Eyes"
API RawData SquidBeakon "{\"seg\": [{},{\"col\": [[255, 255, 255]]}]}"
API Send SquidBeakon

Appendix: Multiple Lamps

This sample sets up SquidBeakon1 and SquidBeakon2 with their own URLs so that they can be driven by separate rewards. Full support for multiple channel point settings is left as an exercise for the reader.

OnInit
API Url SquidBeakon1 "http://192.168.0.113/json/state"
API Method SquidBeakon1 POST
API Header SquidBeakon1 "Content-Type" "application/json"
API Url SquidBeakon2 "http://192.168.0.114/json/state"
API Method SquidBeakon2 POST
API Header SquidBeakon2 "Content-Type" "application/json"
OnChannelPoint "Rainbow Lamp 1"
API RawData SquidBeakon1 "{\"seg\": [{\"of\": 4, \"fx\": 110, \"sx\": 128, \"ix\": 128, \"pal\": 11}]}"
API Send SquidBeakon1

OnChannelPoint "Rainbow Lamp 2"
API RawData SquidBeakon2 "{\"seg\": [{\"of\": 4, \"fx\": 110, \"sx\": 128, \"ix\": 128, \"pal\": 11}]}"
API Send SquidBeakon2

Appendix: Tips for displaying your lamps on stream

The lamps are emitting light, which can be difficult to capture on camera. Some tips to improve the appearance of the lights:

Reflected surfaces

Nearby white or other reflective surfaces will convey the colours of the light

Ambient lighting

The lights will be washed out by bright ambient lighting. The frequencies of sunlight can be especially effective at washing out the lamp colours. Indoor lighting or a dimmed room are best!

Diffusion

A piece of printer paper or baking paper in front of the lights can be used to diffuse the colours. This file contains templates for paper cutouts that can be placed in or on the lamp.

WLED JSON API

The commands in this document send JSON data via the WLED JSON API.

API documentation here:

https://kno.wled.ge/interfaces/json-api/

Posted in: Code, Streaming | Tagged: leds, squid lamp, twitch

Recent Posts

  • Laser-cut Nintendo Switch Webcam Rig
  • Using the USB connection to drive Squid Beakon colours
  • Personalised Splashtag nametags
  • QArt Code Signature Blocks
  • Blogs, Portfolios and Challenges

Archives

  • January 2023
  • December 2022
  • October 2022
  • August 2022
  • May 2022
  • April 2022
  • November 2021
  • September 2021
  • August 2021
  • August 2020
  • September 2019
  • August 2019
  • August 2018
  • May 2018
  • September 2016
  • August 2016
  • October 2015
  • September 2015
  • August 2015
  • April 2015
  • February 2015
  • October 2014
  • August 2014
  • July 2014
  • April 2014
  • March 2014
  • February 2014
  • September 2013
  • August 2013
  • July 2013
  • April 2013
  • March 2013
  • January 2013
  • December 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • May 2012
  • March 2012
  • January 2012
  • December 2011
  • November 2011
  • September 2011
  • August 2011
  • June 2011
  • May 2011
  • March 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • April 2010
  • March 2010

Copyright © 2023 Proairesis.

Theme by themehall.com.