If Then Else

How would I go about a TV time scene that after a trigger and a condition of under 400 lumens outside, turns on scene (i.e. All media components) with lights, otherwise turns on scene without the lights?

I understand the trigger and most of the condition code, but I don’t know how to implement the two final outcomes.

Is this more a job for App daemon? If so is there an example I could make use of?

Thanks

I’ve done something like this with native HA automation.

# MQTT/Harmony
- alias: 'Theater Lights'
  trigger:
    - platform: state
      entity_id: switch.watch_tv
      state: 'on'
    - platform: state
      entity_id: switch.firetvplex
      state: 'on'
    - platform: state
      entity_id: switch.chromecast
      state: 'on'
    - platform: state
      entity_id: switch.bluray
      state: 'on'
  condition:
    condition: sun
    after: sunset
    after_offset: "-00:45:00"
  action:
    - service: scene.turn_on
      entity_id: scene.sunset
    - delay: 00:01:30
    - service: scene.turn_on
      entity_id: scene.sunset_dimmed

The effect is that if I triggered any activity on the Harmony Hub, it would bring the lights up to full, wait a minute and a half and then slowly fade down. But only if it’s getting dark.

I don’t believe there’s a possibility of an “else”. There a couple of ways I’ve handled stuff like this, none are elegant:

  1. For items that are successive or can stack (can’t think of a way to word this), I’ll have a sequence and take advantage of the fact that I can quit from it by using conditions. For instance, I might want a lamp to come on dim in some situations, bright in others. I start with the dim command, then a condition test, then the bright command.

  2. I’ll sometimes call two scripts and plan so that one will fail based on conditions. That’s not so much an “if/else” as an “or”.

I think that this is probably a situation for Appdaemon, but I haven’t tackled using it yet.

1 Like

It was this kind of more complex requirement, specifically an else as well as more nested logic that made me write AppDaemon, this would be a good usecase for a simple App.

Bit of a thread hijack, but where can I find a “getting started” so that I know how to install AppDaemon? I know there’s a Q&A page and a blog post - but I’m not seeing any “getting started” kind of info. Thx!

Tutorial

Install

API Reference

1 Like

Is there a code repository for Apps that people can share? The joy of github is being able to learn by searching millions of examples of code. If not, what would be a good way of providing a catalog of shared code? (Something similar to Share your projects category but for Apps)?

It’s something that’s being worked on. :smiley:

1 Like

^ this.

For now there are some examples distributed with AppDaemon.