UPB lighting

Are you using it to trigger an automation? Can you give me an idea of how your automation is detecting if the scene is being activated or deactivated?

I haven’t actually done it yet. I was going to install it the other day and ran into problems but when I was testing, I did see this (link below) on the event bus when activating a link from a physical switch. I’m not sure if you’ll see a state change (it always stays in “scening”) in hass because the state doesn’t change but you should be able to monitor for the event.

https://pastebin.com/KFzC72ap

I looked at what you posted. Maybe I just don’t see it but how can you tell what happened other than something happened?

I see data.new_state.last_updated is different from data.old_state.last_updated. Something happened to scene.mode_wake_up_2 but I can’t tell what happened to it; it’s unclear (to me) if it was activated or deactivated.

You will see a state change. A new attribute called last_changed is a timestamp of the last change. That is sufficient to trigger a state change automation.

I think I agree with @123 that a bus event is required. Considering that now. Not sure if last_changed should stay or not.

Suggestion… Let’s create issues on github with feature requests, bugs, etc. That way we can keep issues in separate threads, things will not get lost as I know they will here. Open the issues on either the upb-lib or the hass-lib repos as you see fit. Either one will suffice for tracking.

I was reading some other threads dealing with events created by Deconz and ZHA integrations. For example, pushing a button on some flavor of Zigbee remote control will post an event that’s packed with details about what just happened.

It seems to me that this is a good way to express a UPB link’s activity. Was the link activated or deactivated? Was it used with a Goto to set the level and FadeRate? All of that (and more) can be reported by an event.

Examples:

{
    "event_type": "deconz_event",
    "data": {
        "id": "study_button",
        "unique_id": "00:15:8d:00:03:3e:f7:b0",
        "event": 1002
    },
    "origin": "LOCAL",
    "time_fired": "2020-01-30T18:57:16.151335+00:00",
    "context": {
        "id": "30426998b12142bbb7c8b06c241969f2",
        "parent_id": null,
        "user_id": null
    }
}
{
    "event_type": "zha_event",
    "data": {
        "unique_id": "cc:cc:cc:ff:fe:99:12:49:1:0x0008",
        "device_ieee": "cc:cc:cc:ff:fe:99:12:49",
        "endpoint_id": 1,
        "cluster_id": 8,
        "command": "stop",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2020-02-02T15:37:17.393168+00:00",
    "context": {
        "id": "83e0a17834184401b335d55370236542",
        "parent_id": null,
        "user_id": null
    }
}

EDIT

As per Glenn’s suggestion, I’ve posted it as an Issue: https://github.com/gwww/hass-upb/issues/1

I know I pressed the button. Duhh… :slight_smile:

Good points. I never thought about knowing more details about the link. Not something I thought about using but sounds like you’re right that the data should be exposed to do it correctly.

I’m updating github as well. Good point gwww. I subscribed to 123’s issue.

:slight_smile:

OK, I get it. Your application only needs to know the link was transmitted (it doesn’t require details such as if the link was Activated/Deactivated or used with Goto or FadeStart/FadeStop).

In my case, the automation (in Premise) listens for activate/deactivate so it knows which action to perform (turn the associated X10 light on or off). All four of the UPB switch’s buttons are configured so that a single press sends activate and a double press sends deactivate.

I’m very interested in the current developments! Kudos @gwww !!!

I would like to do some testing, but my skills in HA development are weak. Could you aid me in setting this up?

I’m running HA installed manually on a Raspberry Pi. I have a serial PIM with a USB adapter. What would I need to do to get this going? I would assume I’d need to install the library:

pip install upb-lib

And add to my configuraiton.yaml

upb:
    url: serial:///dev/ttyUSB0
    file_path: ./upb.upe

Then copy my upb network export to the configuration home directory

Am I on the right track?

Partly right.

You do not want to install upb-lib. You do want to install hass-upb. To do that grab the latest .zip file from here: https://github.com/gwww/hass-upb/releases. Unzip the downloaded file. In the unzipped content you’ll find a directory custom_components. Copy custom_components AND everything inside it to your config directory on your Raspberry PI. On your PI you should have a /config/custom_components/upb/<all the files from the upb unzipped directory>

Update your configuration.yaml as you have already indicated. Make sure your UPStart export file named upb.upe is in your /config directory on your Pi. Restart hass. Hopefully enjoy.

Thanks for the help! I forgot to mention, I did install the custom_components files. Should I uninstall upb_lib from my venv? I’m getting an error when I do a Check Config:

Invalid config for [upb]: [url] is an invalid option for [upb]. Check: upb->url. (See ?, line ?). 

my ttyUSB0 device is present.

Yah, there’s some config issue I’m trying to figure out. Not sure what is going on but it is feeling like a core hass issue. So, YMMV. I get invalid config too, but hass runs just fine. So you could try it.

No need to uninstall upb_lib. hass installs it for you and if you have the wrong version hass will install the right one.

Good luck!

Invalid config fixed with 0.0.6-alpha build.

1 Like

Do you want to open this as an issue and tag it as “investigate”?

Not at the moment. Maybe later.

I’m currently having difficulty testing UPB events.

  • I’m using 0.0.6-alpha
  • I added upb.scene_activated to Developer tools > Events > Listen to events
  • Clicked Start listening
  • Pressed a button that activates link 2.
  • I see no response in the UI

I changed it to upb.scene_activate but got the same result.

What is your recommended test procedure for evaluating events? Also, where in the source code does it generate events?


EDIT

FWIW, this automation wasn’t triggered when I pressed a button that activates link 2:

- alias: 'UPB event'
  trigger:
  - platform: event
    event_type: upb.scene_activated
  action:
  - service: persistent_notification.create
    data_template:
      message: 'entity_id: {{trigger.event.data.entity_id}}'
      title: 'UPB Scene Activated'

What am I missing here?

Here is what is working for me:

  - id: scene-activated
    alias: "Scene activated"
    trigger:
      platform: event
      event_type: upb.scene_activated
      event_data:
        entity_id: scene.family_room_half
    action:
      service: system_log.write
      data_template:
        message: "Activated '{{trigger.event.data.entity_id}}' Data '{{trigger}}'"

And the log that is generated on a button push:

2020-02-02 22:51:50 ERROR (MainThread) [homeassistant.components.system_log.external] 
Activated 'scene.family_room_half' Data 
'{'platform': 'event', 'event': <Event upb.scene_activated[L]: entity_id=scene.family_room_half>}'

I’m sure I don’t need the event_data on the trigger, but no time to try right now.

The code is in scene.py. Look for fire.

Comment moved to GitHub: https://github.com/gwww/hass-upb/issues/1#issuecomment-581622868

1 Like

New version 0.0.7-alpha release up. Moving fast, so surely some bugs, but heading in a good direction. THANK YOU for all the testing everyone is doing!

@gwww I got everything switched over and I found that bug. Thanks for the wicked-fast turn around. Good timing for all this being the wife wasn’t home tonight.

We’re live!

FYI
Posted new issue: Light entity’s state is unchanged after using upb_light_fade_start service.