thx for your detail explanation and effort. have a good day. glmnet : )
Hi,
I am trying to use this but got confused. Do we have to add following in configuration.yaml? It is giving me error, I guess because ESP is not connected yet. On the other hand, not able to compile code in ESPHOME as its giving error of dfplayer not defined. Any help would be appreciated on how to use dfplayer through ESPHome?
uart:
tx_pin: GPIO2
rx_pin: GPIO5
baud_rate: 9600
# Declare DFPlayer mini module
dfplayer:
on_finished_playback:
then:
logger.log: 'Somebody press play!'
dfplayer is still not bundled with ESPHome, so you need to create a custom_components folder a place the files in there as I explain just above.
I am new to this Home Assistant and I am sorry for a basic question. I have dfplayer module and i have home assistant setup running on hassio (Pi3) . I want to send notification sounds (mp3 recorded) to speaker through wifi. I tried to follow above instructions but failed to make it working. Will someone be kind enough to give me step by step procedure of configuration.
If I copy the 3 files in following folder, then my HA boots OK but configuration file gives error “Component not found: dfplayer”
config/custom_components/dfplayer/
If I copy 3 files in custom components folder directly and restart then my hassio/HA does not boot and I cannot access its web interface.
config/custom_components/
Just noticed following error after the Pi boots.
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 860, in get_code
File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/dfplayer/__init__.py", line 7
<!DOCTYPE html>
^
SyntaxError: invalid syntax
you are confusing the custom_components folder, seems like you are using the one where HA loads custom components, not the one where esphome loads custom components, the folder you want should be in the same folder where your esphome yaml file is.
I believe the folder will be /config/esphome/custom_components
Thank you so much for the guidance. Unfortunately now error changed to “Component dfplayervcannot be loaded via YAML (no CONFIG_SCHEMA)”
Make sure the files contents are ok.
In your previous post looks like there is xml inside the .py file
In github right click raw button for each file and select save link as…
Thanks a million glmnet. It worked. The files were being changed during download, which is fixed by downloading raw. Thank you sooooooo much
hi glmnet ?
I am very happy I can use MP3 player from HA
but I have no idea How to make it from Home Assistant Volume Control
I refred to Servo Motor Integration but I can’t…
Can you guide me Automation.yaml or api setup ?
I am very grateful again for your awesome codes.
I believe what you want is a slider volume in HA?
Then you can use the df player set volume via api, check the sample https://esphome.io/components/dfplayer.html#sample-code
ESPHOME
api:
services:
- service: dfplayer_set_volume
variables:
volume: int
then:
- dfplayer.set_volume: !lambda 'return volume;'
HOME ASSISTANT
it will look something like
input_number:
dfplayer_volume:
name: Volume
initial: 15
min: 0
max: 30
step: 1
automation:
- alias: Set df player volume
trigger:
platform: state
entity_id: input_number.dfplayer_volume
action:
- service: esphome.livingroom_dfplayer_set_volume
data_template:
volume: "{{ states('input_number.dfplayer_volume') | int }}"
Thank you very much, it’s great I’ll check this code right now.
thank you again… : )
I’m just curious , when i do a service call(dfplayer_set_device) from Node Red, whats the parameter in data field? thx
Thanks all for your contributions, I really have been longing for this integration!
- I just followed the instructions and easily got the DFPlayer+Wemos mini integration to work from HA!
I would also like the ESP to directly connect to the door bell switch and send a “play command” to the DFPlayer to play a chime file.
So I added the following lines to the ESPHome yaml:
binary_sensor:
- platform: gpio
pin:
number: 14
inverted: true
name: “Door Bell”
filters:- delayed_on: 50ms
on_press:
then:- dfplayer.set_volume: 25
- dfplayer.play: 001
- delayed_on: 50ms
Now to the problem: after uploading and still in ESPHome “Show Logs”-mode it works perfectly but when I close this mode, the DFPlayer don’t play the file anymore.
- It might have something to do with how the UART works but I don’t know how to debug the problem further.
PS. In HA I can see that the state of the GPIO pin is shifting from off to on when I push the door bell switch.
Anyone managed to get this “local trigger scenario” to work?
This is how the logs looks like when the chime works when I’m in the ESPHome “Show Logs” mode.
As it only fails when I have closed the Show Logs I would like to get a similar trace/log when I have left the “Show Logs” - is that possible?
[22:05:28][C][api:096]: Address: test_mp3.local:6053
[22:05:32][D][binary_sensor:036]: ‘Ringklockan’: Sending state ON
[22:05:32][D][dfplayer:032]: Send Command 0x6 arg 0x19
[22:05:32][D][dfplayer:032]: Send Command 0x3 arg 0x01
[22:05:32][V][dfplayer:074]: Received message cmd: 0x41 arg 0000
[22:05:32][V][dfplayer:103]: Ack ok
[22:05:32][D][binary_sensor:036]: ‘Ringklockan’: Sending state OFF
[22:05:37][V][dfplayer:074]: Received message cmd: 0x3d arg 0x01
[22:05:37][D][main:367]: Playback finished event
[22:05:37][V][dfplayer:074]: Received message cmd: 0x3d arg 0x01
[22:05:37][D][main:367]: Playback finished event
Fixed the problem with inserting a 150mS delay b/w the two commands.
Now its time to get the virtual dog to bark when no one is at home🤗
I would love to try this too!
Anyone has a detailed hardware list and connection scheme I can look at?
I’m trying to get this set up with an ESP32 and can’t even seem to get the file to play. I’m at a loss here but can’t figure out what I’m going wrong. If I watch the log and send commands from the dev tools, this is what I can get. Does the Nack mean it didn’t work? Then what’s up with the Ack ok then?
esphome.mp3_player_dfplayer_set_volume
{ “volume”: 30 }
[16:00:09][D][dfplayer:032]: Send Command 0x6 arg 0x1e
[16:00:09][V][dfplayer:074]: Received message cmd: 0x40 arg 0x01
[16:00:09][V][dfplayer:099]: Nack
[16:00:09][V][dfplayer:103]: Ack ok
esphome.mp3_player_dfplayer_next
[16:08:49][D][dfplayer:032]: Send Command 0x1 arg 0000
[16:08:49][V][dfplayer:074]: Received message cmd: 0x40 arg 0x01
[16:08:49][V][dfplayer:099]: Nack
[16:08:49][V][dfplayer:103]: Ack ok
Any advice or help would be appreciated.
Just for anyone else out there that runs into this issue, I found another site that specified that the sd card for this player must be formatted as FAT16 or FAT32. I’d just tossed in a card that was NTFS. After reformatting, everything works out fine.