I used that chatgpt to see if it can write groovy…

Only I don’t understand groovy, is this b.s?

I said “ Can you write groovy to flash my hue lights 4 different colors?”
And in two seconds

@Grab('com.philips.hue:hue-sdk:2.1.0') // download the Hue SDK

import com.philips.lighting.hue.sdk.* // import necessary classes

// set up connection to Hue bridge
def bridge = new HttpBridge("your_bridge_ip_address", "your_api_key")
def bridgeState = bridge.getBridgeState()

// set up parameters for light state
def lightId = 1 // replace with the ID of your Hue light
def lightState = new LightState()
lightState.setOn(true)
lightState.setAlert(Alert.SELECT)
lightState.setTransitionTime(0) // set transition time to 0 for immediate effect

// set up colors to flash
def colors = [[hue: 0, saturation: 255, brightness: 255], // red
[hue: 21845, saturation: 255, brightness: 255], // green
[hue: 43690, saturation: 255, brightness: 255], // blue
[hue: 65535, saturation: 255, brightness: 255]] // yellow

// loop through colors and flash each one for 1 second
colors.each { color ->
lightState.setHue(color.hue)
lightState.setSaturation(color.saturation)
lightState.setBrightness(color.brightness)
bridge.updateLightState(lightId, lightState)
sleep(1000) // wait for 1 second
}

// turn off lights
lightState.setOn(false)
bridge.updateLightState(lightId, lightState)

// close connection to Hue bridge
bridge.closeConnection()

“ This code uses the Hue SDK to connect to your Hue bridge and set the state of a specific light to flash 4 different colors. You will need to replace "your_bridge_ip_address" and "your_api_key" with the appropriate values for your Hue bridge.

The lightState object is used to specify the desired state of the light. In this case, it turns the light on, sets the alert to "select" (which flashes the light), and sets the transition time to 0 for an immediate effect.

The colors variable is an array of objects that specify the hue, saturation, and brightness values for each color to flash. In this example, the colors are red, green, blue, and yellow.

The code then loops through each color and sets the lightState object to the specified hue, saturation, and brightness values. It then updates the state of the light and waits for 1 second using the sleep method.

After flashing all 4 colors, the code turns off the light by setting the on parameter of lightState to false, updates the state of the light, and closes the connection to the Hue bridge.”

No way this is correct, right?

1 Like

It's possible it is / was correct back in 2021, which I believe was the time when the data ChatGPT uses comes from. Either way, I expect both the progression of the Hue API to a newer version (although v1 I believe is still supported for now), and definitely the need to import the Hue SDK would trip you up.

Like anything, ChatGPT can definitely be useful in giving you a starting point for how to achieve something, you just need to fill in a few gaps or explore things a little more for yourself.

2 Likes

That’s insane, I just found it today

I know, I have used it once or twice for work, with those same caveats around it not always being correct or up to date, just using it to get ideas to investigate more thoroughly. I also like the conversational style, compared to (admittedly more and more advanced) keyword searches in things like Google's search engine.

That is probably fine Groovy (I didn't look too hard), but it's not a Hubitat app or driver, in case that's what you're going for -- it would be a standalone Groovy script.

I did this in the Bing Chat that is using current internet sources and it came up with this:

At the bottom you can see the sources of it's response.

I then asked if it could be made into a Hubitat application and got this:

Yes, it's possible to create a Hubitat application using Groovy that can flash your Hue lights with 4 different colors. You can use the code that I provided as a starting point and modify it to work with Hubitat.

Here's an example of how you can modify the code to work with Hubitat:

definition(
    name: "Flash Hue Lights",
    namespace: "your_namespace_here",
    author: "your_author_name_here",
    description: "Flashes Hue lights with 4 different colors.",
    category: "My Apps",
    iconUrl: "",
    iconX2Url: ""
)

preferences {
    section("Hue Bridge") {
        input "bridgeIp", "text", title: "IP Address", required: true
        input "bridgeUsername", "text", title: "Username", required: true
    }
}

def installed() {
    log.debug "Installed with settings: ${settings}"
}

def updated() {
    log.debug "Updated with settings: ${settings}"
}

def flashHueLights() {
    def hue = new HueBridge(bridgeIp, bridgeUsername)
    def lights = hue.getLights()
    def colors = ["red", "green", "blue", "yellow"]
    def delay = 500
    def count = 0
    while (count < 4) {
        lights.each { light ->
            light.setColor(colors[count])
            light.setOn(true)
        }
        sleep(delay)
        lights.each { light ->
            light.setOn(false)
        }
        count++
    }
}

def runInMinutes = { closure, minutes ->
    runIn(closure, minutes * 60)
}

runInMinutes(flashHueLights, 1)

This code defines a Hubitat application that flashes your Hue lights with 4 different colors. You can modify the bridgeIp and bridgeUsername variables in the preferences section to match your Hue bridge's IP address and username. The flashHueLights function is the same as before.

I hope this helps! Let me know if you have any other questions.

Source: Conversation with Bing, 3/31/2023(1) Hue Bridge Integration | Hubitat Documentation. Hue Bridge Integration | Hubitat Documentation Accessed 3/31/2023.
(2) hubitat/advanced-hue-light-sensor.groovy at master · apwelsh/hubitat. hubitat/hue/device/advanced-hue-light-sensor.groovy at master · apwelsh/hubitat · GitHub Accessed 3/31/2023.
(3) GitHub - HubitatCommunity/CoCoHue: Open-source community-created Hue .... GitHub - HubitatCommunity/CoCoHue: Open-source community-created Hue Bridge integration for Hubitat Accessed 3/31/2023.
(4) [Release] Advanced Hue Bridge Integration - Hubitat. [Release] Advanced Hue Bridge Integration Accessed 3/31/2023.
(5) Connect Phillips Hue to Hubitat - Tips - Hubitat. Connect Phillips Hue to Hubitat Accessed 3/31/2023.

1 Like

Who needs ChatGPT when you can ask the Hubitat Community :slight_smile:

9 Likes

Where is the import for hue bridge code? Did you run this? It doesn’t look like it’s I’ll work as written.

Iknow nothing or I’d try. I’m really curious about how quick can someone make a working app using ai

AI is a long way away from making working code. And all the code generated by AI is plagiarized. So is from open source, and some from closed source, you don’t even know if you code is legal.
In this case, you can see they took code from a Hue library for groovy (or maybe JavaScript) and applied it to the groovy language then applied that same code to Hubitat, but without the necessary context to know that the call to huehub requires a special class for hue hub.

It can certainly help in some areas to get a starting point, but if I saw a developer turn in code like this, I would ask questions which would quickly reveal they didn’t know much and this was AI generated.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.