Applescript and Shell: how do I insert a variable?
You're embedding RandomNumA inside a literal (double-quoted) string, so it's treated as part of the literal rather than as a variable reference. To get it interpreted as a variable, you have to do the same thing you do in the do shell script command at the end -- use &amp; to append a quoted literal, a variable reference, and another quoted literal. Actually, it's slightly more complicated because you have to use parentheses to make sure the whole thing gets quoted form of applied to it:

set RandomNumA to (random number from 0 to 65535)

set TurnOnBulbA to the quoted form of ("{\"on\": true,\"hue\": " &amp; RandomNumA &amp; ", \"sat\": 240,\"bri\": 90}")