Energy usage Neocoolcam plugs connected via toon in domoticz

Everything about external control, apps, VNC, etc goes here.

Moderators: marcelr, TheHogNL, Toonz

Post Reply
copywizard
Starting Member
Starting Member
Posts: 8
Joined: Sat Feb 01, 2020 10:32 pm

Energy usage Neocoolcam plugs connected via toon in domoticz

Post by copywizard »

I have read the whole "controlling Toon via Domoticz" topic from front to back and i see the same question i have pop up sometimes but its never been answered anywhere.

I have a rooted Toon from terrorsource (Still thanks for that!)
I have multiple fibaro and neocoolcam wall plugs connected to Toon
And i have my Toon connected to my Domoticz instance which works fine right now.

What i want is to try and get the current energy usage of all my zwave plugs in domoticz.

I used the tutorial from Maiden to connect some zwave plugs to domoticz but only as switches so they don,t show any energy usage information.

is there a way to see this energy usage per zwave plug in domoticz? en if so how?

any help would be much appriciated
yjb
Member
Member
Posts: 211
Joined: Fri Apr 17, 2009 1:15 pm
Location: Venhuizen, Netherlands

Re: Energy usage Neocoolcam plugs connected via toon in domoticz

Post by yjb »

Hi,

At a high level you will need to run a script from cron that queries the toon, lets say every 5 minutes and inserts the values in domoticz.

Code: Select all

#!/usr/bin/php
<?php

/* Synchronize samrt plug usage information from tToon to Domoticz */
/* 20-10-2018 YJB /
/* 15-11-2018 YJB Added logging */
/* 21/12/2018 YJB Cleaned up code */

/* Instructions:
        - Create Domoticz dummy devices (Electric Instant & Counter), name should match plugname in Toon
        - Make a note of the idx numbers and enter those
        - Place script in Domoticz folder /home/pi/domoticz/scripts/toon/ or desired folder.
        - Make sure Curl is installed (sudo apt-get install php-curl).
        - Make sure script is executable (chmod +x filename.php).
        - Create a new of using an existing crontab file in /etc/cron.d
                Example entry (every 5 minutes): */
                # */5 * * * * root /home/pi/domoticz/scripts/toon/smartplugs_usage.php > /dev/null 2>&1

/* Set IP addresses and idx*/
$IPDomoticz = '127.0.0.1';
$IPToon = 'xxx.xxx.xxx.xxx';
/* idx = array(idx_1, idx_2, idx_3, etc) */
$idx = array(764, 765, 766, 767, 820);

$date_time = date ('Y-m-d H:i');

/* Read the current values from Toon */
$file_string_ElecCounter = file_get_contents("http://$IPToon/hdrv_zwave?action=getDevices.json");
/* If you set the second parameter of json_decode to true, you get an array*/
$parsed_json_ElecCounter = json_decode($file_string_ElecCounter, true);

foreach ($idx as $Index) {

        /* read last recorded total value from Domoticz */
        $json_string = file_get_contents("http://$IPDomoticz/json.htm?type=devices&rid=$Index");
        $parsed_json = json_decode($json_string, true);
        $parsed_json = $parsed_json['result'][0];
        $Counter_Domoticz = $parsed_json['Data']*1000;
        $Name_Domoticz = $parsed_json['Name'];




        foreach($parsed_json_ElecCounter as $device){
                $Counter_Toon = "Empty";
                $Name_Toon = "Empty";
                (isset($device['DeviceName']) && $Name_Toon = $device['DeviceName']);
                if ($Name_Toon == $Name_Domoticz){
                (isset($device['CurrentElectricityQuantity']) && $Counter_Toon = intval($device['CurrentElectricityQuantity']));
                (isset($device['CurrentElectricityQuantity']) && $Current_Flow_Toon = intval($device['CurrentElectricityFlow']));
                $ElecIncrement = $Counter_Toon-$Counter_Domoticz;
/* Debug Only*/
/*                              echo "-----------\n";
                                echo "Name reported by Domoticz: $Name_Domoticz \n";
                                echo "Total Stored in Domoticz = $Counter_Domoticz Wh\n";
                echo "Name reported by Toon: $Name_Toon \n";
                                echo "Total reported by Toon = $Counter_Toon Wh\n";
                                echo "Current flow reported by Toon = $Current_Flow_Toon Wh\n";
                echo "Calculated Increment: $ElecIncrement Wh \n";
*/
                /* write new value to Domoticz */
                if ($Counter_Domoticz == 0){ #this is for the first run only, when the idx is still empty.
                        $WriteInitValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$Index&nvalue=0&svalue=$Current_Flow_Toon;$Counter_Toon");
                        echo "\n";
                        echo "Initialize Counter \n";
                        curl_exec($WriteInitValue);
                        }
                else if ($Counter_Toon < $Counter_Domoticz){
                        error_log("[$date_time] $Name_Domoticz Toon value lower ($ElecIncrement), do nothing. \n", 3, '/var/log/smartplugs_usage-error.log');
                        /* Debug Only*/
/*                                              echo "Toon value lower ($ElecIncrement), do nothing. \n";
                                                $WriteValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$Index&nvalue=0&svalue=$Current_Flow_Toon;$Counter_Toon");
                        curl_exec($WriteValue);
*/
                                                }
                else if ($ElecIncrement >= 2000){
                        echo "Toon value is larger than 2000, do nothing \n";
                        error_log("[$date_time] $Name_Domoticz Toon value is larger than 2000 ($ElecIncrement), Skipped\n", 3, '/var/log/smartplugs_usage-error.log');
                        }
                else if ($Counter_Toon >= $Counter_Domoticz){
                        $WriteValue = curl_init("http://$IPDomoticz/json.htm?type=command&param=udevice&idx=$Index&nvalue=0&svalue=$Current_Flow_Toon;$Counter_Toon");
                        echo "\n";
                        /* Debug Only*/
                        /*echo "Write new value \n";*/
                        /*error_log("[$date_time] $Name_Domoticz Write new value\n", 3, '/var/log/smartplugs_usage-error.log');*/
                        curl_exec($WriteValue);
                        }
                else {
                        echo "Domoticz counter ($Counter_Domoticz) incorrect, do nothing \n";
                                                echo "Toon value ($Counter_Toon) \n";
                        error_log("[$date_time] Domoticz counter ($Counter_Domoticz) incorrect, do nothing \n", 3, '/var/log/smartplugs_usage-error.log');
                        error_log("[$date_time] Toon counter ($Counter_Toon) \n", 3, '/var/log/smartplugs_usage-error.log');
                        }


        }
}

}

?>

I used some snippets from other people, but can't remember who (and I'm not pretending this is mine) and added some stuff. I'm not a php programmer, so it can probably be done more efficient.

The problem is that if you unplug the plug and insert it again it will loose all the values and starts counting from scratch, there are probably ways of dealing with this, but I never bothered to do that
copywizard
Starting Member
Starting Member
Posts: 8
Joined: Sat Feb 01, 2020 10:32 pm

Re: Energy usage Neocoolcam plugs connected via toon in domoticz

Post by copywizard »

Thanks for the quick reply!

i read what you said but i think its better then to just buy a Z-wave stick and connect the Z-wave plugs to that?

and just disconnect them from my toon.
yjb
Member
Member
Posts: 211
Joined: Fri Apr 17, 2009 1:15 pm
Location: Venhuizen, Netherlands

Re: Energy usage Neocoolcam plugs connected via toon in domoticz

Post by yjb »

Not sure why a Z-Wave based solution is better? I guess it just depends on what you want to do.

Keep in mind that loosing the totals will happen with a Z-Wave plug as well, so you will need to find a solution either way.
mAiden
Member
Member
Posts: 330
Joined: Mon Jul 10, 2017 10:22 am

Re: Energy usage Neocoolcam plugs connected via toon in domoticz

Post by mAiden »

When I was still using Domoticz, I had a script that threw this kind of consumption through to Domoticz .. Will have a look tomorrow for you.
Member of the Toon Software Collective
copywizard
Starting Member
Starting Member
Posts: 8
Joined: Sat Feb 01, 2020 10:32 pm

Re: Energy usage Neocoolcam plugs connected via toon in domoticz

Post by copywizard »

Thanks for the replies.

But i already bought a zwave usb stick and got everything working that way and all info is nicely collected into domoticz.

i would only love to figure out a way to combine the wattage and total kWh usage of all 7 zwave plug together in 1 new sensor.
So i dont have to calculate them myself ;)
Post Reply

Return to “Toon external control”