DoESLiverpool / somebody-should

A place to document practices on the wiki and collect issues/suggestions/to-do items for the physical space at DoES Liverpool
31 stars 11 forks source link

Install sensor to record the whole electricity usage in the space #1015

Closed goatchurchprime closed 5 years ago

goatchurchprime commented 5 years ago

Apparently the electricity bills for the heating are costing more than we're spending on 3D printer filament.

Why do we know the cost of filament per metre, but not the cost of the heating box running per minute?

What is the cost of the laser cutter per minute, given that we can monitory it in realtime? Power varies by 3x so etching is not as energy intensive as cutting.

Where is the electricity meter? We could get a rough calibration of the cost of each of our systems (lighting, heating, laser power, pot of coffee, baseline) by running each of these individually for a set time out of hours and recording the difference. The numbers should correspond somewhat to the ratings on the devices.

From the unit costs, the secondary effect costs are the time it takes to raise the temperature by 1degree. This could feed through to a rule that the heating can be put on only when there are N people in the room out of hours; or you've got to pay for it like you would pay for a packet of crisps.

For comfort, we should make available N-1 heated waistcoats: https://www.primrose.co.uk/heated-gilets-jackets-c-37_753.html

None of this is high tech (like OCR of power meter). Just very simple accountancy and curiosity.

amcewen commented 5 years ago

Our meter (for all of our usage) is downstairs... looks like this:

Main electricity meter

goatchurchprime commented 5 years ago

There's a red flashing LED that flashes 10 times for every 0.001 that shows on the LCD screen.

There are arduino pulse counter things projects that watch for these flashes. http://www.reuk.co.uk/wordpress/solar/flashing-led-on-electricity-meter/

If we had to do it, we could plug in an ESP32 powered from the handy mains socket just below it and stuck on with a bit of double-sided foam tape and possibly pick up an MQTT signal count for every pulse in real time.

topic=alldoespower message=[microseconds since last pulse] [pulse count modulo 1000]

The meter in the picture should be one of the ones on this page, but I can't find it exactly: https://www.landisgyr.com/devices/?product-cat=334&product-region=678&product-country=8&keyword=#filter

Many of the options have communications built in, so it should potentially be done through its own interface somewhere. (In my dreams it's got a built-in hotspot that allows us to login and point it to the MQTT server.)

ajlennon commented 5 years ago

I did something very similar to monitor the gas meter in my old house.

ajlennon commented 5 years ago

We could add something to Espurna easily enough I suspect

goatchurchprime commented 5 years ago

The ESP32 device with the light sensor is programmed and ready to be installed. It's been tested outside the door and the wifi reaches it.

photometer

The code installed on it is here:

https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/projects/electricity_meter_flashes_to_mqtt.ipynb

The command to see what it reads is: mosquitto_sub -v -h mqtt.local -t "esp32powflash/#"

The message is composed of 3 numbers separated by spaces: [number of milliseconds since last flash] [duration is flash milliseconds] [flash counter]

goatchurchprime commented 5 years ago

It's now installed and working. It took a while to debug because the duration of the flash is 24 milliseconds, and I was filtering out any spike that was less than 50ms.

The payload format is "[flash period (ms)] [flash duration (ms)] [sequence number]", so esp32powflash/ticks 862 24 8506 is equivalent to 3600/862=4.17kW, because there are 1000 flashes per kWh.

ajlennon commented 5 years ago

Brilliant!

ajlennon commented 5 years ago

What do we need to do to turn this into SI units? Should we handle conversion in the node-red flow?

goatchurchprime commented 5 years ago

The data is conversion is available two ways.

There is one record added to the database per flash.

The nodered converts the milliseconds-since-last-flash to kiloWatts by the formula 3600 / msflashtime and stores it in the database.

The count of the number of records in the database within a set duration (eg from midnight until now()) equals the number of flashes. Divide this number by 1000 and you get the total kWhrs used for the day. Cost is then 15p times this number.

goatchurchprime commented 5 years ago

It stopped working at 7am this morning. I don't know why.

Maybe the code is too simple and it's not catching the exception that can be thrown in from client.publish().

Also, it will probably fail to reconnect if either the router or the mqtt-broker reboots. Maybe I need to base this code on the mqtt_as (asynchronous version) which would look after all that sort of stuff.

ajlennon commented 5 years ago

I meant to suggest to you that we should enable webrepl (unless there's a better way) so we can do remote updates to it in case things break...

ajlennon commented 5 years ago

We should also look at what watchdog capability there is to reset it if/when things bugger up

goatchurchprime commented 5 years ago

Fixed up. Turns out that the device fell off and ripped out its wires. A sticky on the side of the box isn't good enough in such a warm environment, so I've made longer wires for the LDR and placed it on the top of the meter so it is no longer defying gravity.

goatchurchprime commented 5 years ago

The power monitor seems to have fallen offline at around 10pm last night, according to the graph.
Nothing showing up on the MQTT: mosquitto_sub -v -h mqtt.local -t "esp32powflash/#"

Need to get into the room to find out what's happened (has it been unplugged or something)? It won't have fallen off this time.

It would be useful to find out its ip-number so we can ping it. I don't know if it's possible to reboot it remotely when it's crashed. There might be some webrepl service now on ESP32s that could be used to probe what's going on.

johnmckerrell commented 5 years ago

I can try finding out its ip address but it would help if you know anything to describe it, MAC address or if it has a self-assigned hostname. I’d be happy to fix the IP addresses of all the MQTT monitors (although now I think about it, are they actually running off the standard DoES Wi-Fi?)

On 11 Jun 2019, at 16:30, Alex Lennon notifications@github.com wrote:

Webrepl?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DoESLiverpool/somebody-should/issues/1015?email_source=notifications&email_token=AAAGU27TOSAUA2ENUKWZNO3PZ7AHRA5CNFSM4GL7K35KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXNQYPY#issuecomment-500894783, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGU24WPF5KWYKZPDLLCLDPZ7AHRANCNFSM4GL7K35A.

johnmckerrell commented 5 years ago

I've mentioned this to Jason, he's in tomorrow and will let me or Julian into the room to take a look.

goatchurchprime commented 5 years ago

I've got the webrepl on the IR sensor in Room29, and it also puts its IP number on the mqtt gateway, so we can look it up.

Webrepl is a websocket that gives access to the command line, so we can connect to it, find out what the exception is, as well as restart it -- all as if we had a serial connection to it.

(It came as default in ESP8266s, accounting for their amazing bootstrapping abilities, due to a hack that was possible in its version of the TCP libraries.)

johnmckerrell commented 5 years ago

This seems to be down at the moment. It's been up and down a few times since the last update I think. Any update on what's going on with it? We're likely to need the air con on soon and it would be nice to monitor it. I can gain access to the room this morning so if it's a simple power cycle let me know.

johnmckerrell commented 5 years ago

I did power cycle it, not seeing any updates yet but I'll check again later. We have access to the key so can do more if necessary.

ajlennon commented 5 years ago

I think one problem was the LDR sensor had dropped off in the past

johnmckerrell commented 5 years ago

Still not seeing anything, checked again and I can see some lights on the breadboard and the sensor seems to be in the right place (as far as I can tell) so not sure what the problem is.

Just an FYI but Jason might be interested on doing this for the building, at least for 24 hours, as part of an investigation into getting solar installed on the building.

goatchurchprime commented 5 years ago

It's back up. Turns out that the mDNS component of the mqtt.local machine fails after a while. It started working again once I power cycled it.

The code on the power device is very simple and probably can't come up from a hiccup in the service. It's not using the asynchronous mqtt library like a lot of the other devices.

This is another service that needs monitoring for the internal logging watchdog system on the Rpi to find out why or how it fails.

I've updated the current state of knowledge here https://github.com/DoESLiverpool/somebody-should/wiki/ESP-devices

ajlennon commented 5 years ago

This went down again a few days ago. @johnmckerrell power cycled it and it came back up straight away.

ajlennon commented 5 years ago

@goatchurchprime the wiki notes say the power meter is running this code.

https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/Sensor_Kennel/esp8266_MQTT_Main.py.ipynb

Is this correct as I can't see how the "ticks" values are being generated here?

goatchurchprime commented 5 years ago

It's this code, I think:

https://github.com/goatchurchprime/jupyter_micropython_developer_notebooks/blob/master/projects/electricity_meter_flashes_to_mqtt.ipynb

I have updated in the wiki.

The active loop in the code is just doing this:

n, t0 = 0, 0
while True:
    x = machine.time_pulse_us(pdetector, 0, 10000000)//1000
    t = time.ticks_ms()
    dt = t - t0
    client.publish(topicname, "%d %d %d" % (dt, x, n))
    t0 = t
    n += 1
    pled.value(n%2)