Usage template energy meter to add to presence lights

Hi guys, I am fairly new to home automation. I get a lot of info by just searching on the forum pages. Most of the times it helps me enough to figure out the problems I’m facing. As I can’t cope with this specific problem and spent hours on it, I want to ask here to put me in the right directions

I recently added a configuration with a motion detector that switches off the lights in the living room after X minutes without any presence. What happens is that we sit down and occasionally the Neo Coolcam PIR doesn’t see us sitting. I also have a Neo Coolcam power plug with monitor capabilities. What I want to do is telling HA that if the power plug is using more than 10 watts, that the lights are staying on in the living room. The power plug will be used with the tv.

This feature has to complement the code underneath:

1. - alias: 'Lights turn off after 3:30 minutes' 2. trigger: 3. platform: state 4. entity_id: binary_sensor.pir_woonkamer_sensor_6_0 5. to: 'off' 6. for: 7. minutes: 3 8. seconds: 30 9. action: 10. - service: switch.turn_off 11. entity_id: switch.test_lamp_woonkamer 12. - service: switch.turn_off 13. entity_id: switch.grijze_lamp_woonkamer

I’ve also added this, but I keep struggling in filling in the details of ‘value_template’ Note: value template does not consist any good code. Just a summary of what I want it to do.

1. sensor: 2. - platform: yr 3. - platform: template 4. sensors: 5. energy_meter: 6. value_template: "{{ "if >10 W is used, do not turn off the lights" }}" 7. unit_of_measurement: 'W'

I used pages like HA template sensor, but I can’t find answers to what I have to fill in to let it work. I also looked at the templating page, and many other things, but it’s just a bridge too far at the moment to figure it out myself.

I’m looking forward to your answers!

Off the top of my head, I would create a binary template sensor based on the energy measurement value and then use that sensor’s state as a condition in the automation.

You mean like you mentioned in your post here?

So i figure I should add the following lines in my configuration.yaml

[code]sensor:
2. - platform: yr
3. - platform: template
4. sensors:
5. energy_meter:

if using less than 10 Watts

  1.   value_template: "{{ states('sensor.energie_tv_woonkamer_power_8_8') | int < 10 }}"
    
  2.   unit_of_measurement: 'W'[/code]
    

The automation should look something like this?

- alias: 'Lights turn off after 3:30 minutes' trigger: platform: state entity_id: binary_sensor.pir_woonkamer_sensor_6_0 to: 'off' for: minutes: 3 seconds: 30 condition: condition: state entity_id: sensor.energie_tv_woonkamer_power_8_8 state: '<10' action: - service: switch.turn_off entity_id: switch.test_lamp_woonkamer - service: switch.turn_off entity_id: switch.grijze_lamp_woonkamer

This last part I don’t know how to implement.

1 Like

Yes. The state of the template sensor should be either true or false, so I think your condition should test for true/false rather than <10 though. I’m kind of sleepy this morning after a late night so I may be off a bit, but I think that’s right.

Ah ok. So because I made a sensor (template) where the state is less than 10 watts, in the automation it should state ‘true’ because of this.

I’m going to implement it later on and track my progress. Thanks so far! It’s becoming more clear already!

Everything works ok now. I tested everything with the code onderneath. When the tv screen is turned off, the wattage is below 19 W. When fully in use, it is around 54 W. If I now turn off the tv, my light will turn off within the specified time. When the tv is on, it won’t. Yay! It’s getting better and better to understand everything within the code :slight_smile:

[code]sensor:

  • platform: template
    sensors:
    energy_meter:
    value_template: “{{states(‘sensor.energie_tv_woonkamer_power_8_8’) | int < 19 }}”
    unit_of_measurement: W [/code]

[code]automation:

  • alias: ‘Light go out after 20 sec at midnight’
    trigger:
    platform: state
    entity_id: binary_sensor.pir_woonkamer_sensor_6_0
    to: ‘off’
    for:
    seconds: 20
    condition:
    condition: numeric_state
    entity_id: sensor.energie_tv_woonkamer_power_8_8
    below: ‘19’
    action:
    • service: switch.turn_off
      entity_id: switch.lamp_keuken
    • service: switch.turn_off
      entity_id: switch.test_lamp_woonkamer
    • service: switch.turn_off
      entity_id: switch.grijze_lamp_woonkamer[/code]
1 Like