A bot for Telegram and email that can monitor temperatures.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Aaron Johnson 20ca2f3359
Resolved conflicts
6 years ago
example_services Trimmed down fork of EGS-Bot 6 years ago
probe_scripts Added probe scripts 6 years ago
static_text Resolved conflicts 6 years ago
.gitignore Trimmed down fork of EGS-Bot 6 years ago
README.md Updated README 6 years ago
bot_config.yaml.example Updated example config for SSH port 6 years ago
callbacks.rb Added non-standard SSH port support 6 years ago
colors.rb Trimmed down fork of EGS-Bot 6 years ago
commands.rb Fixed logging delays (missing/misplaced STDOUT.flush calls) 6 years ago
fakeoutput.txt Trimmed down fork of EGS-Bot 6 years ago
run.rb Resolved conflicts 6 years ago

README.md

#HeatBot A Ruby application to provide remote temperature probe data over Telegram, to groups or to individuals


##Prerequisites You will need the following packages on your primary bot server:

  • nmap
  • curl
  • ruby As well as these Ruby gems:
  • telegram-bot-ruby
  • yaml
  • time

For each remote temperature probe:

  • bc
  • w1-gpio (kernel module)
  • w1-therm (kernel module)

##Configuration ####bot_config.yaml After cloning this git repo, the first thing you will want to do is copy bot_config.yaml.example to bot_config.yaml and edit the values. Below are the values with a description:

botname: The name of your bot. This is cosmetic, and does not alter any functions. tmpdir: Temporary directory the bot will use when needed. token: Private Bot token. Can be obtained from @botfather on Telegram. admin: This is an array of admin users. Currently, there are no admin-only functions built into the bot at this time. authorized_chats: These are the chat IDs (or user IDs for individual, non-group interaction) in which the bot is allowed to respond with any temperature or self-identifying information. User information will still be provided publicly by design, so you can use /chatinfo to find your own information you need to add to be authorized. allowed_sources: These are the types of messages to allow. By default, all message types are allowed. It is recommended to leave this alone, but the option is there to restrict it further. units: The default temperature unit. Heatbot supports Fahrenheit (F), Celsius (C), Rankine (R or Ra), and Kelvin (K). probes: This is a "hash of hashes" that will identify each remote temperature probe, first by hostname to be used for the SSH connection (shq-example01), then loc: is the human-readable location (Server Room), and port: is the SSH port, default 22, which can be altered in case a non-standard SSH port is used for a particular probe.

####HeatBot systemd Service In the repository, you will find eample/services/heatbot.service. Copy this into /etc/systemd/system/ and edit the copy. Primarily, you will want to edit the username to the desired user to run the service (default is ivo, user must already exist), and be sure the working directory is pointing to your repository location. Please not that symlinks are perfectly valid for this purpose. Once in place, as with any other service, run:

systemctl daemon-reload
systemctl enable heatbot.service #Optional

At this time, the bot has not yet been started. By default, the bot will log to journald when run as a service. The bot's output is colour-coded, and by normal journalctl usage does not show up as intended. You can still read the logs this way, but it will be much easier if you use the --output cat flag with it. To be sure the bot is configured correctly, let's watch the log output during the first start:

systemctl start heatbot.service & journalctl --output cat -fu heatbot

Pay careful attention to the sanity check portion, and if anything comes up with a red FAIL instead of a green OK, address the issue and restart the service and check again.

####SSH Confgiuration (Recommendations) There are many ways you can configure your SSH connections that will work. The bare minimum to function is that the following command must be valid to be run from the primary bot server, and return in Celsius the probe temperature:

ssh -p [port] [host] heatbot_gettemp

The way in which we have achieved this conveniently is by use of the bot server's /etc/hosts file and the bot service user's ~/.ssh/config file. Let's take a look at an example set up. Let's say we are using a bot_config.yaml with the following probes: hash:

probes:
    probe01:
        loc: 'Server Room'
        port: 22
    probe02:
        loc: 'Garage'
        port: 22

Let's also say that these hosts, probe01 and probe02, use the respective IP addresses 10.0.0.1 and 10.0.0.2 and both probes have SSH set up for the user heatbot. The user that is running the service in our example is ivo. Under this topology, we would configure the bot server as such: ######/etc/hosts

10.0.0.1    probe01
10.0.0.2    probe02

######~ivo/.ssh/config

Host probe01
    User heatbot
    PasswordAuthentication no
    PubKeyAuthentication yes

Host probe02
    User heatbot
    PasswordAuthentication no
    PubKeyAuthentication yes

Next, you will want to be check your configuration by making sure your bot user can run the following commands, and succesffully retrieves the expected Celsius temperature value. Please note: You will not be able to retrieve this info until the below Probe Configuration section is completed.

ssh -p 22 probe01 heatbot_gettemp
ssh -p 22 probe02 heatbot_gettemp

If all is set up well, you will simply receive a decimal number and nothing else.

####Probe Configuration There are a large number of ways a remote probe can be configured, even outside of the intended operation. The included probe script is based on obtaining temperature readings from a DS18B20 probe connected to a Raspberry Pi. Let's assume this is the setup, and that you have basic working knowledge of setting up SSH keys and users. The following checklist should be sufficient to complete the setup:

  • Add the following line to /boot/config.txt:
dtoverlay=w1-gpio,gpiopin=4
  • Clone the git repo to each temperature probe host.
  • Copy probe_scripts/heatbot_gettemp to a $PATH that is readable by the heatbot user, or whichever user you decide to use to interact with the probe. /usr/bin/ is a good default location that is sure to be readily read and executed.
  • Edit the copy, changing the configurable line to show the address of your temperature probe. This address will look like 28-[somehexnumbers] as a symlink under /sys/bus/w1/devices/ on the probe.
  • Setup ~heatbot/.ssh/authorized_keys to allow passwordless SSH from the primary bot server's service user.

If all is in order, you should be abel to run locally on the probe the heatbot_gettemp command from the heatbot user, which will return a decimal number. A secondary test would be to attempt the test from the above section, and test running the script remotely from the primary bot server, using, for example:

ssh -p 22 probe01 heatbot_gettemp

Setup Complete

If anything appears to be missing or needs further clarification, drop us a note and we can get the documentation updated.