Logitech harmony command as a switch

Thanks @Jer78 I tried the attr like this

switch:
      tv_stuen:
        value_template: "{{ is_state_attr('remote.hub_stuen', 'current_activity', 'Se Film og TV')}}"
        turn_on:
          service: script.turn_on
          entity_id: script.tv_stuen_activity_on
        turn_off:
          service: script.turn_on
          entity_id: script.tv_stuen_activity_off 

And like before the switch turns on TV and flickers back to off again?
my hub is named remote.hub_stuen and the activity is from the Harmony.conf file generated by HA

It should temporarily flicker off because the remote hasn’t updated the activity right away but it should turn itself back on within seconds. Can you see if that works after a few seconds?

This is what I use without scripts:

specifically:

        xbox_one:
          value_template: "{{ is_state_attr('remote.living_room', 'current_activity', 'Xbox One') }}"
          turn_on:
            service: remote.turn_on
            data:
              entity_id: remote.living_room
              activity: 'Xbox One'
          turn_off:
            service: remote.turn_on
            data:
              entity_id: remote.living_room
              activity: 'PowerOff'

You can treat the turn_on and turn_off sections as scripts themselves. Like this one:

        audio_1:
          value_template: "{{ is_state_attr('media_player.yamaha_receiver', 'source', 'Echo') and is_state('switch.floating_outlet_switch', 'on') }}"
          turn_on:
            - service: switch.turn_on
              entity_id: switch.floating_outlet_switch
            - service: media_player.turn_on
              entity_id: media_player.yamaha_receiver
            - service: media_player.select_source
              data:
                entity_id: media_player.yamaha_receiver
                source: Echo
            - service: media_player.volume_set
              data:
                entity_id: media_player.yamaha_receiver
                volume_level: 0.7
          turn_off:
            - service: switch.turn_off
              entity_id: switch.floating_outlet_switch
            - service: media_player.turn_off
              entity_id: media_player.yamaha_receiver

@petro looks interesting! but I havent started to use lovelace, to much time getting it just working! :slight_smile:
@Jer78 YOUR RIGHT! - THANKS ALLOT - I Just needed a little patience! It goes back after some seconds!

Thanks again @Jer78 I have been reading allot of your post and I found your input to using a “input_select”
(I would still need the above switch setup with Home kit and Google assistant! ) does it still work?

If I can bother you with one more question, using this input select like this (I have two Hubs):

input_select:
  hub_stuen:
    name: TV stuen
    options:
      - 'Select Activity'
      - 'Se Film og TV'
      - 'Lyt til Sonos'
      - 'PowerOff'
    initial: 'Select Activity'
    icon: mdi:television
  hub_aktivitet:
    name: TV Aktivitetsrum
    options:
       - 'Select Activity'
       - 'Play a PS4 Game'
       - 'Play a Wii Game'
       - 'Chromecast'
       - 'PowerOff'
    initial: 'Select Activity'
    icon: mdi:monitor

I would need the my activities, I found different examples one that used automation scripts and another I dont really know what is? script? - I haven’t been able to find out how to insert this to my configuration file?
Do you still use this?
automation: ???

- alias: 'tv stue controls'
  initial_state: true
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_select.hub_stuen
  action:
    - service: remote.turn_on
      data_template:  
        entity_id: remote.hub_stuen
        activity: >-
          {% if is_state("input_select.hub_stuen", "PowerOff") %}-1
          {% elif is_state("input_select.hub_stuen", "Se Film og TV") %}25355972
          {% elif is_state("input_select.hub_stuen", "Lyt til Sonos") %}25359950
          {% endif %}
    - service: input_select.select_option
      entity_id: input_select.hub_stuen
      data_template:
        option: "Select Activity"

I also found other setup like the above but that had 2 automation (Allot of code to get this working!)
1) # Will update the input select when the activity is changed using the harmony remote or other device
2) # will start an Harmony activity once it’s selected from the input select in the frontend

But if I am correct the above code doesn’t need this?
Still new to this but I am a quick learner (At least that’s what I tell myself LOL)
Again thanks this forum is a lifesaver!
Best regards
Casperse

Ignore the lovelace bits. I just linked that post because it contains many variations of switch templates using the harmony hub.

If you are using the switch templates you don’t need the input_select.

Your attached automation will not update the input_select. A second automation is needed for that.

Yes, that’s what the automation does.

If you are referring to the Switch templates, yes you are correct. You don’t need any of this.

1 Like

Thanks @petro !!!

For voice I really need the switch but for the hass.io UI the selection would be nice LOL
(Google assistant can only pair with one hub, creating switches solves that limitations!)
Seems the second part above is also automation: ? and not a script:

- alias: 'tv stue controls'
  initial_state: true
  hide_entity: true
  trigger:
    - platform: state
...etc

But according to you I would still need the above extra automations 2 hubs x 2 automations like this?:

automation:

# Will update the input select when the activity is changed using the harmony remote or other device

  - alias: 'Remote external update stuen'
    trigger:
      platform: state
      entity_id: remote.hub_stuen
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.hub_stuen
        option: >
          {{ states.remote.hub_stuen.attributes.current_activity }}
        
  - alias: 'Remote external update aktivitetsrum'
    trigger:
      platform: state
      entity_id: remote.hub_aktivitet
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.hub_aktivitet
        option: >
          {{ states.remote.hub_aktivitet.attributes.current_activity }}
  

# will start an Harmony activity once it’s selected from the input select in the frontend

  - alias: 'Remote start activity from input select stuen'
    trigger:
      platform: state
      entity_id: input_select.hub_stuen
    action:
      service: script.turn_on
      entity_id: script.input_select_harmony_stuen

  - alias: 'Remote start activity from input select aktivitetsrum'
    trigger:
      platform: state
      entity_id: input_select.hub_aktivitet
    action:
      service: script.turn_on
      entity_id: script.input_select_harmony_aktivitetsrum

Yes, those automations are needed for the input_selects to work. One automation that changes the remote via the interface. And one automation that changes the interface via the remote.

@petro YES! its actually working, the missing bit was that I couldn’t tell that it as automation and not a script

One thing, when I select the drop down and an activity, it goes back to the standard “Select Activity” I would like it to stay on the selected activity? - I have initial: Select Activity but that shouldn’t be the problem?

input_select:
  hub_stuen:
    name: TV stuen
    options:
      - 'Select Activity'
      - 'Se Film og TV'
      - 'Lyt til Sonos'
      - 'PowerOff'
    initial: 'Select Activity'
    icon: mdi:television

I’m guessing that one of your scripts handles that for you. Check these 2 scripts and make sure they aren’t setting back the input_select to defualts: input_select_harmony_aktivitetsrum, input_select_harmony_stuen

automation:

  - alias: 'tv stue controls'
    initial_state: true
    hide_entity: true
    trigger:
      - platform: state
        entity_id: input_select.hub_stuen
    action:
      - service: remote.turn_on
        data_template:  
          entity_id: remote.hub_stuen
          activity: >-
            {% if is_state("input_select.hub_stuen", "PowerOff") %}-1
            {% elif is_state("input_select.hub_stuen", "Se Film og TV") %}25355972
            {% elif is_state("input_select.hub_stuen", "Lyt til Sonos") %}25359950
            {% endif %}
      - service: input_select.select_option
        entity_id: input_select.hub_stuen
        data_template:                    <--------This &
          option: "Select Activity"     <-------- This line?

@petro Also found this but doesn’t seem to be working:

  data_template:
    option: "Select Activity"
    option: option: '{{ states.remote.hub_stuen.attributes.current_activity }}'

just remove all of this:

      - service: input_select.select_option
        entity_id: input_select.hub_stuen
        data_template:                    <--------This &
          option: "Select Activity"     <-------- This line?

Thanks @petro everything works now!

Looking at your setup and icons it looks really nice! - is all the plugins native to hass.io?
I have everything in switches or light now (Except my Zones are all Sonos but that have so far been to complicated to get working, just wish there was a easy way to get it working with google assistant (Sonos should come out with something soon?)… not to impressed by it - it was just released last week supporting danish…I can see you have a ECHO to bad it doesn’t support danish yet
Thanks again this has been a great learning experience for me

1 Like

Yes, everything in that is native to home assistant, it just requires you to enable Lovelace.

@casperse glad you got it all working and @petro was able to help. Sorry I had been away all day and couldn’t jump in but looks like you are up and running.

I find I don’t use the input_select ever since Lovelace because the button cards do a better job. I also combine them with conditional cards to only show when the tv is on or if the room sensors are active. Just a few ideas for you. Let me know if you’re interested and I can post my lovelace code.

@Jer78 Yes I would be very happy to also look at your setup!

I am so happy the Google assistant now finally understand “Turn on TV” as a switch through Harmony, the native Harmony link never worked and only supported one HUB, and now I keep getting synch. errors even if I removed the link - What a Sh*tty way of doing a commercial integration

Anyway some quick question to both of you, would help me do things the right way :wink:

  • How do you control voice commands like sound levels on your amplifier?

  • Through Harmony remote as a switch? level 10, 20,30…

  • I can see that @petro have a HA supported receiver, and I believe I also might have one a “Pioneer” would that then be able to be controlled directly?

  • What about pause, Play, Mute do you have all of these as specific switch for each Harmony command? do they need to be linked to a specific activity?

  • I have been putting off Sonos integration for a very long time (I know @Jer78 have had allot of experience with that) so far I have been waiting for Sonos to come through with their voice integration for all platform (I am not a fan of IFTTT so I really don’t want to go down that road) would just Mute all Sonos speakers and Stop all playback be simple to do?

Oh another separate thing (For a separate thread) my configuration file is all in one file and it is truly getting really big. I hesitate to split it up in the already made sections, because I feel I would lack the big picture. Best option would be to put anything related to a specific task in one file “!include harmony.yaml” , but I don’t see that option available I would end up with pieces of code in multiple files like scripts, switch, automation, configuration right?

Again thanks for your valuable input spending your time to help me out, much appreciated :+1:

I don’t know about google assistant but i’ll answer these as if you are using alexa.

I used haaska, but currently I use nothing. You could fake out a volume slider as a template light and use alexa that way. I helped a guy do that here, but the code would be different for the level_template and set_level sections.

Pretty much you would treat it like a light: “Alexa, turn on Volume to 50%”.

That depends, can this component be used with your receiver? If yes, then use this.

Play would be best handled as a script, even pause. But it still won’t be phonetic because you’d have to treat it like a light or switch. The main issue here is that alexa doesn’t support these commands. The play, pause, and change volume all directly change alexa’s media (I’d expect the same behavior from GA).

Or the simplest and best solution… just use the proper buttons on the Harmony remote, the always work first time every time, don’t need to shout to compete when you have the volume to loud, don’t get Alexa doing random things because she couldn’t hear what you said or was more interested in following whatever was said on the telly than you etc etc.

Voice commands are great for a lot of things, as are screen based remotes, but for remote media consumption you still can’t beat a real button :slight_smile:

1 Like

What if he has no arms?

1 Like

I think he’d be after doing more than just turning the volume up in that case :smile:

1 Like

@casperse

Here’s the part of my lovelace config that shows controls for the basement harmony when I’m around. Note: I’m using the custom button card as it has more functionality than the newly added lovelace one that got added in 0.81. Just search the forum for it to install the custom file.

######################################################################################################
#                      BASEMENT DYNAMIC CONTROLS                                                     #
######################################################################################################
        - type: conditional
          conditions:
            - entity: input_boolean.home_scene
              state: "on"
            - entity: binary_sensor.display_basement_dynamic_controls
              state: "on"
          card:
            type: vertical-stack
            cards:
              - type: entities
                show_header_toggle: false
                title: Basement
                entities:
                  - entity: input_number.denon_volume
                  - entity: group.basement_ceiling
                    icon: mdi:lightbulb
                  - entity: light.basement_floor_lamp
                    icon: mdi:floor-lamp
              - type: horizontal-stack
                cards:
                  - type: "custom:button-card"
                    entity: switch.media_center
                    icon: mdi:apple
                    color_type: card
                    color: var(--primary-color) #cool green color rgb(223, 255, 97)
                    color_off: var(--dark-background-color)
                  - type: "custom:button-card"
                    entity: switch.fire_tv_basement
                    icon: mdi:amazon
                    color_type: card
                    color: var(--primary-color) #cool green color rgb(223, 255, 97)
                    color_off: var(--dark-background-color)
                  - type: "custom:button-card"
                    entity: switch.xbox
                    icon: mdi:xbox
                    color_type: card
                    color: var(--primary-color) #cool green color rgb(223, 255, 97)
                    color_off: var(--dark-background-color)
                  - type: "custom:button-card"
                    entity: switch.wii_u
                    icon: mdi:wiiu
                    color_type: card
                    color: var(--primary-color) #cool green color rgb(223, 255, 97)
                    color_off: var(--dark-background-color)

I do have a template binary sensor that determines whether it should display or not based on an Ecobee sensor and the remote activity, here’s that portion of it:

  display_basement_dynamic_controls:
    entity_id:
      - binary_sensor.basement_occupancy
      - remote.basement
    value_template: >-
      {% set occupancy = states.binary_sensor.basement_occupancy.state %}
      {% set remote = states.remote.basement.state %}
      {% if occupancy == "on" or remote == "on" %}true
      {% else %}false
      {% endif %}