Combining different binary sensors

I cannot combine binary TOD sensors and other binary sensors in one packade . Generates an error . If I move binary TOD sensors to another package, everything works . How to connect in one package different binary sensors ?



grid_city:


  template:
    - binary_sensor:
        - name: spm90_voltages
          unique_id: spm90_voltages
          delay_off:
            minutes: 3
          state: >
            {{ states('sensor.spm90_voltage')|float(default=0) < 380 }}



        - name: grid_city_on
          unique_id: grid_city_on
          state: >
            {% set voltage = is_state('binary_sensor.spm90_voltages', 'on') %}
            {% set high_tariff = is_state('binary_sensor.high_tariff_morning', 'on') or 
            is_state('binary_sensor.high_tariff_evening', 'on') %}
            {{ voltage and high_tariff }}

      # Π”Π΅ΡˆΠ΅Π²ΠΈΠΉ Ρ‚Π°Ρ€Ρ–Ρ„ Ρ€Π°Π½ΠΎΠΊ
        - platform: tod
          name: high_tariff_morning
          unique_id: high_tariff_morning
          after: "08:00"
          before: "11:00"

        # Π”Π΅ΡˆΠ΅Π²ΠΈΠΉ Ρ‚Π°Ρ€Ρ–Ρ„ Π²Π΅Ρ‡Ρ–Ρ€
        - platform: tod
          name: high_tariff_evening
          unique_id: high_tariff_evening
          after: "20:00"
          before: "22:00"
            
        

  automation:


    - id: auto_turn_grid_low_battery
      alias: auto_turn_grid_low_battery          
      initial_state: true
      trigger:
      - platform: state
        entity_id: binary_sensor.grid_city_on
        to: 'on'
      - platform: state
        entity_id: binary_sensor.grid_city_on
        to: 'off'   
        
      action:  
        - choose:
          - conditions:
            - condition: state
              entity_id: binary_sensor.grid_city_on
              state: 'on'          
            sequence:
            - service: switch.turn_on
              data:
                entity_id: switch.0xa4c1386199f45931
          - conditions:
            - condition: state
              entity_id: binary_sensor.grid_city_on
              state: 'off'          
            sequence:
            - service: switch.turn_off
              data:
                entity_id: switch.0xa4c1386199f45931                
                
                

                



Please don’t post screenshots but actual yaml, properly formatted. This way we cannot copy/paste etc.

You are mixing two binary sensor types. This binary sensor is under template, so it is a template binary sensor, not a tod binary sensor.

The tod sensor needs to by inder binary sensor at top level.

I raised the TOD sensors to the upper level. The error did not go away
Help please

grid_city:



    template:
 
      binary_sensor:

        - platform: tod
          name: high_tariff_morning
          unique_id: high_tariff_morning
          after: "08:00"
          before: "11:00"

        # Π”Π΅ΡˆΠ΅Π²ΠΈΠΉ Ρ‚Π°Ρ€Ρ–Ρ„ Π²Π΅Ρ‡Ρ–Ρ€
        - platform: tod
          name: high_tariff_evening
          unique_id: high_tariff_evening
          after: "20:00"
          before: "22:00"     

          
        - name: spm90_voltages
          unique_id: spm90_voltages
          delay_off:
            minutes: 3
          state: >
            {{ states('sensor.spm90_voltage')|float(default=0) < 380 }}         


        - name: grid_city_on
          unique_id: grid_city_on
          state: >
            {% set voltage = is_state('binary_sensor.spm90_voltages', 'on') %}
            {% set high_tariff = is_state('binary_sensor.high_tariff_morning', 'on') or 
            is_state('binary_sensor.high_tariff_evening', 'on') %}
            {{ voltage and high_tariff }}

            
        

    automation:


          - id: auto_turn_grid_low_battery
            alias: auto_turn_grid_low_battery          
            initial_state: true
            trigger:
            - platform: state
              entity_id: binary_sensor.grid_city_on
              to: 'on'
            - platform: state
              entity_id: binary_sensor.grid_city_on
              to: 'off'   
              
            action:  
              - choose:
                - conditions:
                  - condition: state
                    entity_id: binary_sensor.grid_city_on
                    state: 'on'          
                  sequence:
                  - service: switch.turn_on
                    data:
                      entity_id: switch.0xa4c1386199f45931
                - conditions:
                  - condition: state
                    entity_id: binary_sensor.grid_city_on
                    state: 'off'          
                  sequence:
                  - service: switch.turn_off
                    data:
                      entity_id: switch.0xa4c1386199f45931                
                      
                

                



No, you did not, there’s still template: above it, that should not be there.

Compare that with the docs:

# Example configuration.yaml entry
binary_sensor:
  - platform: tod
1 Like

Everything works. Thank you for your help

1 Like