Detect electricity meters pulses

I’ve got an electricity coin meter in the corner of my house that has an LED that flashes once per watt hour of electricity used.

I’ve been searching the forum, but I can’t find how to feed that data into openhab. I’m thinking of a simple photodiode circuit over the LED and feed the signal in to my raspberry pi. Can anyone point me in the direction of how to feed this data into openhab and then have it convert it into a current power reading and cumulative power consumption reading for the day?

Cheers

If OpenHAB is tunnin on the Same RPi, you could have a look at the GPIO binding. Or you could wire the phototransistorbto an Arduino/ESP and connector that to OpenHAB with mqtt or even directly to the rest API.

For the tracking portion:

1 Create a Number item for use as the current day running accumulator

  • Name it something like CurrentDayWattHours, RunningWattHours, etc.
  • This item should be persisted
  • This item should be set to restore on startup

2 Create a Number item for use as the end of day total

  • Name it something like PreviousDayWattHours, EndOfDayWattHours, etc.
  • This item should be persisted
  • This may or may not need to be set to restore on startup based on your needs
  • You can use this item for charts to see total usage by day

3 Create a rule to increment the current day accumulator

  • Trigger based on an Off to On pulse of the photodiode
  • In the script of the rule:
    • If the current state of CurrentDayWattHours is invalid (NULL, UnDef, < 0) then set it to 0
    • Add one to CurrentDayWattHours

4 Create a rule to handle day transitions

  • Trigger when the time is midnight
  • In the script of the rule:
    • Move the value of CurrentDayWattHours to PreviousDayWattHours
    • Set CurrentDayWattHours to 0

I can feed the signal from the photo diode into the raspberry pi that openhab is running on without too much hassle. I’ve never done anything on raspberry pi before, only Arduino, so I guess I’ll have to look into key binding? And then I guess feeding that directly into openhab?

I’ll order an easy to wire light sensor, wait for it to arrive and have a play.

Is there a tutorial lurking somewhere that details things like completely custom data inputs? I’ve got a diy off grid solar panel setup and batteries that in the future I’d love to feed in things like battery voltage and total watt hours generated in the last day etc, so I guess I could apply the knowledge gained here to that in the near future.

I understand the raspberry pi doesn’t have any analogue inputs, so an intermediate ADC etc will be required of course.

When you get the sensor can you post some more info and maybe few photos of it? I’ve been searching for this kind of sensor to read my meter also.

So I’ve just to do the whole thing manually from start to end? I’m really surprised that there’s not a semi automated way to set this up. I would have thought that most smart homes have their mains power consumption being fed into the system.

So I’ve got the sensor hooked up to GPIO pin4 and have created a Contact which succesfully goes from “closed” to “open” when I shine a torch on it. I’ve also set up a widget in habpanel that shows “open” and “closed” when I shine the torch on it.

However today is my first ever day with a Raspberry Pi and also my first day ever using openhab, so I’m rather confused by how to set up the rules for increasing the number and making it persistent etc.

I’ve sucessfully created a number called “CurrentDayWattHours” as a starting point, but I can’t work out how to get it to increase by 1 everytime the contact changes state.

So far my code is:

rule "count_todays_pulses"
	when CurrentDayWattHours.state == null
	then CurrentDayWattHours = 0
	
	
	when
		Item Main_meter changed from OPEN to CLOSED
	then
		postUpdate(CurrentDayWattHours, CurrentDayWattHours.intValue + 1)
end


but I keep getting errors no matter what I try.

[6,2]: no viable alternative at input 'when'

[7,8]: no viable alternative at input 'Main_meter'

[7,32]: no viable alternative at input 'OPEN'

[7,40]: no viable alternative at input 'CLOSED'

2018-01-09 00:17:42.972 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Meter_reading.rules' has errors, therefore ignoring it: [2,7]: no viable alternative at input 'CurrentDayWattHours'

[6,2]: no viable alternative at input 'when'

[7,8]: no viable alternative at input 'Main_meter'

[7,32]: no viable alternative at input 'OPEN'

[7,40]: no viable alternative at input 'CLOSED'

Can you help?

Anyone?

Here is one example of how this can be done.

rule "count_todays_pulses"
when
    Item Main_meter changed from OPEN to CLOSED
then
    var newValue = 0
     
    if ((CurrentDayWattHours.state instanceof DecimalType) && ((CurrentDayWattHours.state as DecimalType).intValue() > 0)) {
        newValue = (CurrentDayWattHours.state as DecimalType).intValue()
    }
    
    newValue = newValue + 1
    
    CurrentDayWattHours.postUpdate(newValue)
end