Table of Contents
Bash scripts to:
Scripts use Smappee local API to control plugs and to get the Smappee data. A dummy sensor and Domoticz API is used to push the data.
I saw the initial great and original idea in Domoticz Forums so all the credit goes to user niceandeasy.
I just improved the bash script code and documented this repo to help other users to set it up and added a secondary script to control Smappee plugs.
Any other suggestion will be welcome and pull-requests are welcome too.
3 basic commands are required in the script:
To ensure you have them all, just do the following:
sudo apt-get update && sudo apt-get install curl sed bc
Clone this repo
git clone https://github.com/apazga/smappee-domoticz-bash.git
Create the directory where the script will be (or use the one you prefer)
mkdir -p /home/pi/_scripts/crons
Copy smappee_bash_extractor.sh to the desired location
cp smappee-domoticz-bash/smappee_bash_extractor.sh /home/pi/_scripts/crons
Add a new "Smappee" hardware in your Domoticz server as "Dummy (Does nothing, use for virtual switches only)"
Add four new "Virtual Sensors" to this new hardware (from Hardware list, button "Create Virtual Sensors"):
Name: Energy Consumption
Type: Electric (Instant+counter)
Name: Voltage
Type: Voltage
Name: Ampere
Type: Ampere (1 phase)
Name: Cos Phi
Type: Custom sensor
Edit required variables in smappee_bash_extractor.sh
script. You should configure all variables included in "User configurable values zone".
WARNING: Check twice the idx for each variable in your Domoticz Device list to ensure all match, to avoid "pushing" data to a different sensor
You should configure the following variables:
Test it before setting it as a cron job
cd /home/pi/_scripts/crons
chmod u+x smappee_bash_extractor.sh
./smappee_bash_extractor.sh
Add the following line to your user crontab (crontab -e
)
*/1 * * * * /home/pi/_scripts/crons/smappee_bash_extractor.sh
Due to we are writing every minute, it's highly recommended to create a RAM disk.
To simplify the process, if you want to create 1 MByte RAM disk in your /var/tmp directory, just add the following line at the end of /etc/fstab
and do sudo mount -a
or reboot
.
tmpfs /var/tmp tmpfs nodev,nosuid,size=1M 0 0
More info and RAM Disk tutorial here: http://www.domoticz.com/wiki/Setting_up_a_RAM_drive_on_Raspberry_Pi
First, in your Domoticz server terminal
Copy smappee_plug_control.sh to the desired location
cp smappee-domoticz-bash/smappee_plug_control.sh /home/pi/_scripts/
Edit the script to set your Smappee IP.
Run the script with "list" parameter to list your available plugs using the local API.
chmod u+x smappee_plug_control.sh
./smappee_plug_control.sh list
You'll see an output like this one:
Listing available plugs
Login...
{"success":"Logon successful!","header":"Logon to the monitor portal successful..."}
Available plugs:
[{"value":"My plug 1 ","key":"1"},{"value":"My plug 2 ","key":"3"}]
Then, in your Domoticz web:
Add a new "Manual Switch" in your Domoticz server and use Switch Type "On/Off" and Type "X10" (type isn't important here).
Edit your new switch and set these scripts as "on/off" actions:
On action: script:///home/pi/_scripts/smappee_plug_control.sh 1 3
Off action: script:///home/pi/_scripts/smappee_plug_control.sh 0 3
These commands should power on/off the plug with key (id) 3, that will be "My plug 2" from the previous example.