Credentials and Settings Files - Resinchem/YouTube-to-HomeAssistant GitHub Wiki
Credentials and Settings
These two files (Credentials.h and Settings.h) must be updated to match your environment prior to uploading the sketch to your ESP8266 board. These are provided as separate files so that future updates to the primary .ino file do not overwrite these options and require re-entry on each new version. However, it is possible that future releases may include new features that require updated settings and credential files, forcing you to overwrite your current files. For this reason, it is recommended that you make backup copies of these two files outside of your sketch folder once you have updated them. You will then have a record of the settings should they need to be reapplied on a future update.
Credentials.h
This file holds your login information and other settings that are unique to your environment and that you will want to keep private. They are generally self-explanatory, but are describe here anyway:
DEFINE VALUE | DESCRIPTION |
---|---|
SID "your_SSID" |
The SSID of your Wifi (must be same SSID as Tailwind |
PW "your_password" |
Your WiFi password |
MQTTUSERNAME "your_mqtt_user" |
User name for MQTT broker |
MQTTPWD "your_mqtt_password" |
Password for MQTT broker |
MQTTPORT 1883 |
Port of MQTT broker |
AP_SSID "youtube_ap" |
Optional hotspot to broadcast (see Settings) |
AP_PWD "12345678" |
Password for optional hotspot (see Settings) |
API_KEY "your-very-long-api-key" |
Your YouTube API Key (see below) |
CHANNEL_ID "your-youtube-channel-id" |
YouTube channel ID |
You must obtain a YouTube API key. See Getting Started with the YouTube API and follow the instructions to get your key.
Settings.h
These are settings and options you may wish to update for your install. They are listed in a summary table here, but described in more detail below.
SETTING/Example | Valid Values and Notes |
---|---|
WIFIMODE 2 |
0=AP mode only, 1=Wifi only, 2=both |
MQTTMODE 1 |
0 or 1 - enable/disable MQTT |
MQTTCLIENT "YouTubeClient" |
MQTT Client name - must be unique on your network |
MQTT_TOPIC_SUB "cmnd/youtube" |
Default topic bridge listens on |
MQTT_TOPIC_PUB "stat/youtube" |
Default topic bridge publishes to |
OTA_HOSTNAME "youtubeOTA" |
Hostname broadcast for OTA updates |
ota_flag = true; |
Enable or disable over-the-air updates |
ota_boot_time_window = 2500; |
Time (ms) to initialize OTA on boot |
ota_time_window = 20000; |
Window (ms) to start an OTA update |
timeBetweenRequests = 120000; |
How often (ms) to poll YouTube for stats (in milliseconds) |
ha_discovery = false; |
Enable/disable Home Assistant MQTT Discovery (v1.10 and later) |
Detailed settings descriptions
WIFI MODE
The bridge can broadcast a local hotspot in addition to, or instead of, connecting to your WiFi Network. The hotspot broadcast will be the AP_SSID
you defined in the Credentials.h file. Currently, this option must be set to either 1 or 2 to communicate with your MQTT broker and the YouTube API. Option 0 is reserved for future use and potential uploading of BIN files where credentials and settings may be stored in flash memory.
MQTTMODE
This enables or disables MQTT functionality. Obviously, it needs to be set to 1 for the bridge to function. Option 0 is reserved for future use.
MQTTCLIENT
Each MQTT client on your network must have a unique name. This can be any string value you wish, as long as no other MQTT clients use that name.
MQTT_TOPIC_SUB
This is the topic that the bridge will subscribe to (/#) and generally the topic you will use when issuing commands to the YouTube API (currently, the bridge does not support sending commands to the API). It can be any valid MQTT topic and can be a simple or compound topic. For example, you could use a simple topic such as "youtube
" or compound such as "cmnd/youtube
" depending on how you wish to use or group your MQTT topics. Do not include a leading or trailing slash (/) in the topic. Commands issued to this topic should not have the retained flag set (retain=false
), or ghost commands may occur upon reboot of the broker or bridge.
MQTT_TOPIC_PUB
This is the topic that the bridge will report states and statuses (e.g. total views, subscriber count, etc.). The topic follows the same naming rules as the MQTT_TOPIC_SUB
. However, these topics will be sent with the retained flag set to true (retain=true
), as the states need to be maintained between restarts and not expire, resulting in an unknown state.
ota_flag
This enables or disables the ability to upload new code via over-the-air updates. If set to false
updates must be performed via USB.
ota_boot_time_window
(milliseconds)
For the board to begin broadcasting via mDNS for OTA updates, the OTA process much be initialized for a short time on boot up. If too short, the board may not show up as a port in the IDE. Too long and it just delays the boot time. I've found about 2.5 seconds (2500 ms) is the sweet spot. If your board does not show up as a port in the IDE, you may need to tweak this time.
ota_time_window
(milliseconds)
When the board is placed into OTA mode for uploading (see OTA updating for how to do this), it enters a blocking mode. If an upload does not begin in this window, the OTA process is exited and the bridge returns to normal operation. However, since it is a blocking process, allowing too long of a window may result in the ESP8266 watchdog times causing a reboot of the board. I've found that 20 seconds (20000 ms) is a safe window to avoid reboots. But this does mean that you must have the code verified and ready to go as soon as the board is put into OTA update mode. You can experiment with this value, but if you notice the board rebooting before an OTA starts, trying shortening this window.
timeBetweenRequests
(milliseconds)
This is how often the bridge will poll the YouTube API for state changes. Google utilizes a quota and point system on how often APIs can be polled in a given day. Currently, this is 10,000 points a day. The API used here, using 1 point each time it is called. You can set this value to limit how often the bridge calls the API. I recommend setting to something like 60,000 (one minute) or 120,000 (two minutes) or even longer.
ha_discovery
This enables or disables Home Assistant MQTT Discovery. If enabled, all available sensors are automatically created in Home Assistant and they do not need to be defined manually via YAML. See the Wiki topic MQTT \ Home Assistant for more details on the sensors that are created if this option is enabled. Only available in releases v1.10 and later.