#Trying to switch from IOBroker to Homeassistant / problems migrating automations/scripts

1 messages · Page 1 of 1 (latest)

strange schooner
#

Hi,

i'm trying to switch from IOBroker to Homeassistant so i'm realy new to Homeassistant.

For a few years i am using IOBroker to control my smart devices. Mainly Ikea Zigbee devices. So i installes Zigbee2mqtt on a Kubernetes host besides Homeassistant and NodeRED.

But i can't find a way to have a system similar to the Javascript functions in IOBroker. In IOBroker one can completly write automations in Javascript.

So a small part of a script i'm trying to create in either NodeRED, pyscript or plain Homeassistant and i'm failing hard:

on({ id: idBrightStop, change: "ne" }, async function (obj) {
    if (obj.state.val) {
        if (DEBUG == true) console.log("Stoppe Timer");
        setState(idLevelMove, 0);
    }
});
 
on({ id: idBrightUp, change: "ne" }, async function (obj) {
    if (obj.state.val) {
         if (DEBUG == true) console.log("Starte Timer");
        setState(idLevelMove, 100);
    }
});

on({ id: idBrightDown, change: "ne" }, async function (obj) {
    if (obj.state.val) {
        if (DEBUG == true) console.log("Starte Timer");
        setState(idLevelMove, -100);
    }
});

This part of the script watches the Button on / off on the remote beeing held triggering the brightness_up / brightness_down actions and moving the brightness up untill brightness_stop is published.

is there some way i can do something like this in homeassistant? I realy dislike dragging blocks or IFTTT like logics...

pyscript has the problem that i can't figure out how i could trigger on actions from the remote.

ancient shadow
#

so this is an MQTT topic?

#

i'm not sure where I got topic from

#

ignore that

#

anyways, the remote needs to send this information to HA in order to action off it.

#

We'd need that info in order to show you what to do

strange schooner
#

that is one thing i can't realy figure out.. i tried to figure out the button action id's with develop -> events but with state_changed i can't get anything when i press a button, but a automation with the on action for the button seams to work..

strange schooner
#

i think i got something that somewhat does what i want, but it's realy choppy when changing the brightness by holding the button... and i can't understand why.

# pyscript: ikea_remote.py

light_mqtt_topic = "zigbee2mqtt/arbeitszimmer"
color_temp_min = 250
color_temp_max = 450
color_temp_step = 20

@event_trigger("arbeitszimmer_fernbedienung_action")
def ikea_remote_handler(**kwargs):
    action = kwargs.get("action")
    log.info(f"IKEA Remote Action: {action}")

    if action == "brightness_stop":
        log.info("Brightness STOP – sending MQTT brightness_stop")
        mqtt.publish(f"{light_mqtt_topic}/set", {"brightness_stop": True})

    elif action == "brightness_move_up":
        log.info("Brightness UP – sending MQTT brightness_move 100")
        mqtt.publish(f"{light_mqtt_topic}/set", {"brightness_move": 100})

    elif action == "brightness_move_down":
        log.info("Brightness DOWN – sending MQTT brightness_move -100")
        mqtt.publish(f"{light_mqtt_topic}/set", {"brightness_move": -100})

    elif action == "arrow_left_click":
        log.info("ColorTemp DOWN")
        ct = state.get(f"light.arbeitszimmer", attribute="color_temp")
        if ct is not None:
            if ct <= color_temp_min:
                log.warning("Min ColorTemp erreicht")
                mqtt.publish(f"{light_mqtt_topic}/set", {"effect": "blink", "color_temp": color_temp_min})
            else:
                mqtt.publish(f"{light_mqtt_topic}/set", {"color_temp": ct - color_temp_step})

    elif action == "arrow_right_click":
        log.info("ColorTemp UP")
        ct = state.get(f"light.arbeitszimmer", attribute="color_temp")
        if ct is not None:
            if ct >= color_temp_max:
                log.warning("Max ColorTemp erreicht")
                mqtt.publish(f"{light_mqtt_topic}/set", {"effect": "blink", "color_temp": color_temp_max})
            else:
                mqtt.publish(f"{light_mqtt_topic}/set", {"color_temp": ct + color_temp_step})
ancient shadow
#

ah, it's a Z2M remote?

strange schooner
#

it's one of those ikea remotes that is connected through z2m. i tried with state_trigger, but i can't find a state for the remote in HA

ancient shadow
#

basically, there's a number of ways to do this

#

and it's not straightforward

#

nore easy

#

Go to your device in HA, there should be an MQTT integration. In the device page, you should see an event entity.

strange schooner
#

I can see those entities, so action is missing.. but i can't understand why.... oh. btw the script from above never worked... i just forgot that i had the nodered functions i created enabled too...

ancient shadow
#

that's not the right page

#

go to the MQTT integration, click on devices, then click the device.

#

don't go to the entities page

#

that will show you a list of active entities only, the device page shows you active and disabled entities

strange schooner
#

no action there either :/

ancient shadow
#

check your settings in Z2M, you likely need to turn on things on that side

strange schooner
#

i can't find anything that looks like it would make the action available to homeassistant...

ancient shadow
#

settings -> Home assistant integration?

#

should be 2 checkboxes, one for each potential event type

#

lastly, you can always watch the MQTT topic where the event stream is coming from

strange schooner
#

those are the settings for homeassistent in zigbee2mqtt

ancient shadow
#

right

#

you have both of them off

#

those enable event entities or legacy action sensors

#

both do what you'd expect. Also, there's the topic you can snoop too

strange schooner
#

gnarf... yeah enabling experimental event entities gives me the action in the device... hopefully i can go on from there... but for now i have to go to bed... many many thanks for your help!!!