HASS automation: conditional change work mode

Hi,

I’m trying to set up foxess_rs485_work_mode (foxess modbus) so, that between 5:00 AM and 12:15 PM the “work mode” should be set to “Feed-in First”, but only if battery SOC is above 50%. In all other situations the “work mode” shoud be set as “Self Use”.

- alias: "Change PV Work Mode"
  trigger:
    - platform: time
      after: "05:00:00"
      before: "12:15:00"
  action:
    - if:
        - condition: numeric_state
          entity_id: sensor.foxess_rs485_battery_soc
          above: 50
      then:
        - service: select.select_option
          target:
            entity_id: select.foxess_rs485_work_mode
          data:
            option: "Feed-in First"
      else:
        - service: select.select_option
          target:
            entity_id: select.foxess_rs485_work_mode
          data:
            option: "Self Use"

do you have any Idea what is here wrong or if I can do this better?
Do you have any Idea how to activate this automation only between Mai and August?

Time Trigger supports only one option named at.

It doesn’t support after and before therefore the Time Trigger you created is invalid.

    - platform: time
      after: "05:00:00"
      before: "12:15:00"

Where did you get the idea to use those invalid options?

Welcome to the forum!

The time trigger has no after or before options – only at.

Option 1, if you want a single automation:

- alias: "Change PV Work Mode"
  trigger:
    - platform: time
      at: "05:00:00"
      id: "set"
    - platform: time
      at: "12:15:00"
      id: "reset"
  action:
    - if:
        # conditions are and by default
        - condition: numeric_state
          entity_id: sensor.foxess_rs485_battery_soc
          above: 50
        - condition: trigger
          id: "set"
      then:
        # set
        - service: select.select_option
          target:
            entity_id: select.foxess_rs485_work_mode
          data:
            option: "Feed-in First"
      else:
        # reset
        - service: select.select_option
          target:
            entity_id: select.foxess_rs485_work_mode
          data:
            option: "Self Use"

Option 2, as two automations:

- alias: "Change PV Work Mode to Feed-in First"
  trigger:
    - platform: time
      at: "05:00:00"
  action:
    - service: select.select_option
      target:
        entity_id: select.foxess_rs485_work_mode
      data:
        option: "Feed-in First"

- alias: "Change PV Work Mode to Self Use"
  trigger:
    - platform: time
      at: "12:15:00"
  action:
    - service: select.select_option
      target:
        entity_id: select.foxess_rs485_work_mode
      data:
        option: "Self Use"

Taras might have even neater solutions. :slight_smile:

I’m curious to know too where you found the incorrect syntax.

Hello,

thank you for your reply. I used time settings from time-condition, but as you wrote it was incorrect.
Today I could create extended automation that works for me, but as trigger I used battery soc.

- alias: "Change PV Work Mode v2"
  trigger:
    - platform: numeric_state
      entity_id:
        - sensor.foxess_rs485_battery_soc
      above: 50
  action:
    # IF
    - choose:
        - conditions:
            - condition: time
              after: "05:00:00"
              before: "12:15:00"
            - condition: numeric_state
              entity_id:
                - sensor.foxess_rs485_battery_soc
              above: 70
          sequence:
            - service: select.select_option
              target:
                entity_id: select.foxess_rs485_work_mode
              data:
                option: Feed-in First
        # ELIF
        - conditions:
            - condition: time
              after: "05:00:00"
              before: "10:15:00"
          sequence:
            - service: select.select_option
              target:
                entity_id: select.foxess_rs485_work_mode
              data:
                option: Feed-in First
      # ELSE
      default:
        - service: select.select_option
          target:
            entity_id: select.foxess_rs485_work_mode
          data:
            option: Self Use

Now I need to analyse both examples and create script tailored to my needs :slight_smile:

If somebody needs that code, I’ve change the trigger because it was used only once if the value was higher than 50%. Now I check the value every 15 Minutes

- alias: Change PV Work Mode v2
  trigger:
    platform: time_pattern
    minutes: /15
  condition:
    - condition: time
      after: 07:59:00
      before: "15:16:00"
  action:
    - choose:
        - conditions:
            - condition: time
              after: 07:59:00
              before: "14:59:00"
            - condition: numeric_state
              entity_id:
                - sensor.foxess_rs485_battery_soc
              above: 50
          sequence:
...