NorthernMan54 / node-red-contrib-homebridge-automation

Homebridge and Node-RED Integration
Apache License 2.0
106 stars 18 forks source link

hb-control node output? #64

Open hepcat72 opened 3 years ago

hepcat72 commented 3 years ago

I was constructing a workflow that involves multiple homebridge devices and their toggles need to happen sequentially. For example, I need to:

  1. Switch my HDMI switch to channel 3 (so that my raspberry pi can send CEC commands to the TV)
  2. Turn on the TV (so I can switch the TV's HDMI inputs)
  3. Switch the TV's HDMI input to HDMI 2

These commands are all issued via hb-control instructions and command 2 is slow because the TV's boot up time averages around 20-30 seconds. If command 3 is issued before the TV is done turning on, it doesn't work. Currently, I've implemented a delay, but it would be nice if hb-control had an output (with a status I could check?) so I wouldn't have to have the delay.

That said, I could implement a loop where I check the status of the devices in steps 1 & 2 and only proceed once they have changed to what I expect. However, given my experience with the homekit bridged node, I'm not sure whether I can have multiple hb-status instances of the same device, which I would need for different flows. Can you tell me whether that would cause a problem?

BTW, I'm on version 0.0.62. Sorry if this is already addressed in the current version...

NorthernMan54 commented 3 years ago

In your setup do you know when the TV is actually on ? If you can tap into this, then it could trigger the next step.

I haven't tried this, but I believe the hb-event node should emit a message based on the status change

hepcat72 commented 3 years ago

I do. However there are multiple flows that turn the TV on. And Sometimes I don't actually want HDMI 2, so I wouldn't want the TV powering on to always switch it to HDMI 2. In fact, I'm going to create a few flows that activate HDMI 1 after it turns on... So, could I do that with multiple copies of the hb-status node for the TV - one for each flow where I do something different after the TV turns on? Would there be a problem with multiple copies? I was thinking about creating a subflow that wraps hb-control and hb-status inside a loop* so that the subflow node actually mimics my imagining of hb-control having an output, although I've run into gotchas before WRT subflow nodes not being real until they're called, so it might not work.

* My cec stuff is really unreliable, possibly due to the TV. The TV stops responding to cec power commands unless I do it on the command line. A cec command to turn on (from node-red or homwbridge) only ever works the first time after bootup. So I use an IR blaster to control the power from homebridge/node-red. Although, a command line call to echo "pow 0" | cec-client -s -d 1 seems to work reliably. The only commands in node-red cec nodes and homebridge plugins that seem somewhat reliable is switching HDMI inputs.

NorthernMan54 commented 3 years ago

@hepcat72 What tv do you have? I have an older LG that I control via RS-232 ( This is well documented by LG ) I use this rather than cec for mine.

Would there be a problem with multiple copies ? I have never tried multiple copies, but a couple should be okay.

hepcat72 commented 3 years ago

I spent a good part of yesterday implementing the loop I envisioned. It works well enough. It's just more complicated than I would want.

I pass in the target HDMI switch channel and the target HDMI TV channel and save those to flow variables. I switch the HDMI switch to channel 3 (so the Pi can talk to the TV), turn on the TV via the RM Mini 3 (IR blaster), then enter the loop where I see if the TV is on yet. If it's not, I sleep and loop again (max, 10 tries). If it's on, I switch the the target TV HDMI channel, then switch the HDMI switch to its target channel.

So feel free to close this issue if you'd like. I could try multiple copies to not have to have the loop, but since it works now, I'll probably stop messing with it. I could also try a subflow to hide the loop complexity, but I've definitely had issues with both of those strategies using homekit-bridged before, so I'm not optimistic either of those would be problem free.

Regarding the TV, it's a Magnavox 32ME303V/F7A.

hepcat72 commented 3 years ago

I should probably prevent future entries into the loop while one loop is running. I can just see my wife, repeatedly trying to switch to one of the 4 computers, wondering why it's taking so long.

NorthernMan54 commented 3 years ago

LOL

Good luck

slobatch commented 3 years ago

@NorthernMan54 fwiw, I think the functionality @hepcat72 requested makes sense, though I have a much more straightforward use-case. I'd simply like to log successful hb-control node execution although ideally i'd also be able to log (or catch) failures.