Skip to content

Commit

Permalink
Add Nous A1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjswan committed Dec 13, 2023
1 parent 1215d1b commit d291ded
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/binary_sensor/nous_a1_overpowering.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
platform: template
name: "${name} Overpowering"
id: overpowering
device_class: problem
9 changes: 9 additions & 0 deletions common/binary_sensor/nous_a1_relay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Nous A1 Toggle Relay On/Off
platform: gpio
pin:
number: GPIO13
mode: INPUT_PULLUP
inverted: True
id: button_state
on_press:
- switch.toggle: button_switch
26 changes: 26 additions & 0 deletions common/boot/nous_a1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on_boot:
priority: 600
then:
- binary_sensor.template.publish:
id: overpowering
state: OFF
- if:
condition:
lambda: 'return id(power_on_default).state == "On";'
then:
- switch.turn_on: button_switch
- switch.turn_on: relay
- output.turn_on: led_blue
else:
- if:
condition:
lambda: 'return id(power_on_default).state == "Last" and id(relay).state;'
then:
- switch.turn_on: button_switch
- switch.turn_on: relay
- output.turn_on: led_blue
else:
- switch.turn_off: button_switch
- switch.turn_off: relay
- output.turn_off: led_blue

3 changes: 3 additions & 0 deletions common/esp/esp8266_8285_restore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
esp8266:
board: esp8285
restore_from_flash: true
5 changes: 5 additions & 0 deletions common/led/blue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output:
- platform: gpio
pin: GPIO02
inverted: true
id: led_blue
5 changes: 5 additions & 0 deletions common/led/status.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
status_led:
pin:
number: ${status_gpio}
inverted: True
id: led_status
12 changes: 12 additions & 0 deletions common/select/power_on_default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
platform: template
name: "${name} Power On Default"
id: power_on_default
icon: mdi:power
options:
- "On"
- "Off"
- "Last"
initial_option: "Off"
restore_value: true
optimistic: true
entity_category: config
72 changes: 72 additions & 0 deletions common/sensor/nous_a1_hlw8012.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO05
cf1_pin: GPIO04
change_mode_every: 5
current_resistor: ${current_res}
voltage_divider: ${voltage_div}
update_interval: 5s

current:
name: "${name} Current"
unit_of_measurement: A
accuracy_decimals: 3
# icon: mdi:current-ac
device_class: current
state_class: measurement
filters:
# Map from sensor -> measured value
- calibrate_linear:
- 0.000 -> 0.000
- ${amperage_calibration1}
- ${amperage_calibration2}
- ${amperage_calibration3}
# Furthermore it corrects ${amperage_min}A for the power usage of the plug.
- lambda: if (x <= ${amperage_min}) return 0; else return x;
- median:
window_size: 5
send_every: 3

voltage:
name: "${name} Voltage"
unit_of_measurement: V
accuracy_decimals: 1
#icon: mdi:flash-outline
device_class: voltage
state_class: measurement
filters:
# Map from sensor -> measured value
- calibrate_linear:
- 0.0 -> 0.0
- ${voltage_calibration1}
- ${voltage_calibration2}
- median:
window_size: 5
send_every: 3

power:
name: "${name} Power"
unit_of_measurement: W
id: power
# icon: mdi:gauge
device_class: power
state_class: measurement
accuracy_decimals: 1
filters:
# Map from sensor -> measured value
- calibrate_linear:
- 0.00 -> 0.00
- ${wattage_calibration1}
- ${wattage_calibration2}
- ${wattage_calibration3}
# Make everything below ${wattage_min}W appear as just 0W.
- lambda: if (x <= ${wattage_min}) return 0; else return x;
on_value_range:
- above: ${max_power}
then:
- switch.turn_off: button_switch
- binary_sensor.template.publish:
id: overpowering
state: ON
11 changes: 11 additions & 0 deletions common/switch/nous_a1_relay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
platform: gpio
pin: GPIO15
id: relay
restore_mode: RESTORE_DEFAULT_OFF
on_turn_on:
- binary_sensor.template.publish:
id: overpowering
state: OFF
- output.turn_on: led_blue
on_turn_off:
- output.turn_off: led_blue
9 changes: 9 additions & 0 deletions common/switch/nous_a1_switch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
platform: template
name: "${name} Switch"
# icon: mdi:flash
optimistic: true
id: button_switch
turn_on_action:
- switch.turn_on: relay
turn_off_action:
- switch.turn_off: relay
32 changes: 32 additions & 0 deletions nous_a1_socket.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
substitutions:
device: esp_nous_socket
name: Nous A1 Socket
location: ${name}
update_interval: 60s
device_ip: 192.168.0.0
reboot_timeout: 15min
comment: "Nous A1"

# Higher value gives lower watt readout
current_res: "0.0012"
# Lower value gives lower voltage readout
voltage_div: "771"
# Max power
max_power: "2500"

amperage_calibration1: "0.441 -> 0.459"
amperage_calibration2: "3.495 -> 3.635"
amperage_calibration3: "7.872 -> 8.188"
amperage_min: "0.07"

voltage_calibration1: "229.4 -> 225.9"
voltage_calibration2: "234.0 -> 230.4"

wattage_calibration1: "193.77 -> 99.60"
wattage_calibration2: "1559.22 -> 795.10"
wattage_calibration3: "3464.41 -> 1775.93"
wattage_min: "1.5"

packages:
common: !include packages/common_8266.yaml
nous: !include packages/nous_a1.yaml
23 changes: 23 additions & 0 deletions packages/common_8266.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Common sensors for ESP8266

binary_sensor:
# ESP Status
- !include ../common/binary_sensor/status.yaml

text_sensor:
# ESPHome Version
- !include ../common/text_sensor/version.yaml

# Uptime
- !include ../common/text_sensor/uptime.yaml

sensor:
# Uptime
- !include ../common/sensor/uptime.yaml

# WiFi Signal
- !include ../common/sensor/wifi-signal.yaml

switch:
# Restart
- !include ../common/switch/restart.yaml
52 changes: 52 additions & 0 deletions packages/nous_a1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Nous A1

substitutions:
status_gpio: GPIO00 # - Red, GPIO02 - Blue
energy_method: right
project_name: "ajs.nous_a1_socket"
project_version: "1.0.5"

esphome:
name: ${device}
comment: $comment
build_path: ./.build/$device
project:
name: $project_name
version: $project_version
<<: !include ../common/boot/nous_a1.yaml

<<: !include ../common/esp/esp8266_8285_restore.yaml

<<: !include ../common/common.yaml

<<: !include ../common/led/status.yaml
<<: !include ../common/led/blue.yaml
#<<: !include ../common/led/red.yaml

binary_sensor:
# Nous A1 Toggle Relay On/Off
- !include ../common/binary_sensor/nous_a1_relay.yaml

# Nous A1 Overpowering
- !include ../common/binary_sensor/nous_a1_overpowering.yaml

sensor:
# Nous A1 Today Usage
- !include ../common/sensor/energy_today_usage.yaml

# Nous A1 HLW8012
- !include ../common/sensor/nous_a1_hlw8012.yaml

select:
# Nous A1 Power On Default
- !include ../common/select/power_on_default.yaml

switch:
# Nous A1 Switch
- !include ../common/switch/nous_a1_switch.yaml

# Nous A1 Relay
- !include ../common/switch/nous_a1_relay.yaml

# Gosund SP111 - https://www.esphome-devices.com/devices/Gosund-SP111
# Nous A1 - https://github.com/esphome/issues/issues/1146

0 comments on commit d291ded

Please sign in to comment.